Skip to content

Instantly share code, notes, and snippets.

@tomhodgins
Created June 19, 2012 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomhodgins/2954650 to your computer and use it in GitHub Desktop.
Save tomhodgins/2954650 to your computer and use it in GitHub Desktop.
Site and SQL backup for MediaTemple servers
#!/bin/sh
#####################################################################
## ##
## Welcome to the server backup script, before backing up your ##
## files be sure to update your SQL username and password below ##
## ##
## This script assumes you have folders 'server' and 'databases' ##
## already created inside your /root/backup/ folder ##
## ##
#####################################################################
### This is the site folder backup
cd /var/www/vhosts/
ls > /root/backup/server/filenames.txt
cat /root/backup/server/filenames.txt | xargs -IR tar -czvf '/root/backup/server/R.tar.gz' 'R'
rm /root/backup/server/filenames.txt
echo all websites backed up to /root/backup/server/
### This is the SQL database backup
for T in `mysql -N -B -e 'show databases' -u admin -p password`;
do echo $T;
mysqldump -u admin -p password $T | gzip -c > /root/backup/databases/$T.sql.gz;
done
echo all databases backed up to /root/backup/databases/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment