Last active
November 23, 2018 13:46
-
-
Save madeindjs/607dab00255ec09479a6098e71a2b73b to your computer and use it in GitHub Desktop.
Create a dated backup for my server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# colors | |
green='\e[0;32m' | |
darkred='\e[1;31m' | |
lightblue='\e[1;34m' | |
defaut='\033[0m' | |
# importants variables | |
today=$(date +%Y-%m-%d) | |
foldername_save="isignif_${today}" | |
folder_save="/home/isignif/save/${foldername_save}" | |
sqldump_filename="dump_${today}.sql" | |
websites=(isignif test_isignif) | |
echo -e "${darkred}**SCRIPT TO BACKUP MYSQL & shared files***${defaut}" | |
# Save MySQL | |
echo -e "\r\n${lightblue}1 # MySQL Dump${defaut}" | |
mkdir -p $folder_save | |
cd $folder_save | |
# TODO: set password here | |
mysqldump -u isignif -p"password" --all-databases > $sqldump_filename | |
# save all shared files (valid only for RoR application deployed with Capistrano) | |
echo -e "\r\n${lightblue}2 # Copy shared files${defaut}" | |
for website in ${websites[*]} | |
do | |
mkdir -p "${website}/shared/public" | |
cp -r "/var/www/${website}/shared/config" "${website}/shared/" | |
cp -r "/var/www/${website}/shared/log" "${website}/shared/" | |
cp -r "/var/www/${website}/shared/public/uploads ${website}/shared/public/" | |
done | |
# Copy all pacha conf (for what is worth) | |
echo -e "\r\n${lightblue}3 # Copy Apache conf${defaut}" | |
mkdir apache2 | |
cp -r /etc/apache2/ apache2/ | |
echo -e "\r\n${lightblue}4 # Make an archive${defaut}" | |
cd /home/isignif/save | |
tar -czvf "$foldername_save.tar.gz" $folder_save | |
echo -e "\r\n${lightblue}5 # Remove old archive${defaut}" | |
rm -r "$folder_save" | |
echo -e "\r\n${green}** DONE **${defaut}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment