Last active
August 29, 2015 14:20
-
-
Save coreysan/a263fb38d526ea814605 to your computer and use it in GitHub Desktop.
Download files & a database from a remote server
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 | |
############################## | |
# Backup web server to tgz # | |
############################## | |
# ** Change values like this: [#specific-to-your-server#] | |
# This script SSH'es onto the server then : | |
# - dumps the mysql database | |
# - tars the db and the WordPress wp-content directory | |
# - downloads the file to ~/Documents/backups/ | |
curr_time=$(date +%F_%H.%M.%S) | |
dir_to_backup="/var/www/vhosts/[#site dir#]/wp-content" | |
db_output=[#dbname#]${curr_time}.sql | |
dest=~/Documents/backups/"[#website name#]_server_backup_"${curr_time}.tgz | |
printf "\n\nBacking up the [#website name#] server & database...\n" | |
#ssh to act's server, tar it, return it. | |
ssh [#server username; ie: root#]@[#server ip address#] "cd /var/www/vhosts/[#site dir#]/ && mysqldump -u [#db username#] -p [#db name#] > ${db_output} && tar -czf - ${dir_to_backup} ${db_output}" >${dest} | |
printf "\nArchived web files and database:\n$(du -hs $dest)\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment