Created
December 9, 2016 13:30
-
-
Save timbillstrom/42bf7d0e40e85825eee0749f7afdd7d2 to your computer and use it in GitHub Desktop.
Bash - Backup DB and site files to Dropbox folder.
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 | |
backup_path="/backup/$(date +"%y-%m-%d")/$(date +"%H-%M")-backup" | |
initdump () { | |
mkdir -p /tmp_backup | |
dump | |
storage | |
} | |
dump () { | |
# Backs up database | |
# Database credentials | |
user="" | |
password="" | |
host="" | |
db_name="" | |
mkdir -p $backup_path | |
date=$(date +"%d-%b-%Y-%H%M") | |
# Set default file permissions | |
umask 177 | |
# Dump database into SQL file | |
mysqldump --user=$user --password=$password --host=$host $db_name > $backup_path/$db_name-$date.sql | |
# Backs up site | |
# Moves files to temp folder | |
cp -a /var/www/html/. $backup_path/wordpress/ | |
} | |
storage () { | |
# Saves all the files | |
zip_filename=wordpress-$(date +"%y-%m-%d-%H%M%S") | |
tar -zcvf /tmp_backup/$zip_filename.tar.gz $backup_path | |
curl -H "Authorization: Bearer <token>" https://api-content.dropbox.com/1/files_put/auto/ -T /tmp_backup/$zip_filename.tar.gz | |
rm -rf /backup | |
} | |
initdump |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment