Created
January 25, 2013 20:11
-
-
Save sosukeinu/4637435 to your computer and use it in GitHub Desktop.
BASH backup script
This file contains 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 | |
year="$1" | |
month="$2" | |
day="$3" | |
server_name='interactivedept' | |
backup_repository() { | |
repo_name="$1" | |
svnadmin hotcopy /home/repo/$repo_name /home/backup/$repo_name-repo | |
zip -r /home/backup/$repo_name-repo.zip /home/backup/$repo_name-repo | |
rm -R /home/backup/$repo_name-repo | |
} | |
backup_database() { | |
db_name="$1" | |
mysqldump -u root -pBCG_dev12 $db_name > /home/backup/$db_name-mysql.sql | |
} | |
backup_wordpress_uploads() { | |
project_name="$1" | |
zip -r /home/backup/$project_name-uploads.zip /home/www/$project_name/wp-content/uploads | |
} | |
backup_rails_public() { | |
project_name="$1" | |
zip -r /home/backup/$project_name-public.zip /home/www/$project_name/public | |
} | |
if [ "$3" == "" ]; then | |
echo 'Usage: $ full-backup.sh [year] [month] [day]' | |
else | |
# create backup folders | |
ssh [email protected] "mkdir -p /home/backup" | |
mkdir -p /home/backup | |
# insert backup commands here | |
# backup_repository atc | |
# backup_database atc | |
# backup_wordpress_uploads atc | |
# create the zip file | |
zip -rj /home/backups/$server_name-$year-$month-$day.zip /home/backups | |
# upload to backup server | |
scp /home/backups/$server_name-$year-$month-$day.zip [email protected]:/home/backup/$year/$month/ | |
# clean up | |
rm -R /home/backups | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment