More Backup Script

I made a couple of post-script edits to the original post about the server backup script. Now that I know it works; I decided to start adding to it.

#!/bin/bash

DATE=$(date +%Y%m%d)
mysqldump -u root --all-databases > /var/www/full.sql
tar -cf /var/www/etc-nginx.tar /etc/nginx
tar -czf /root/backup-$DATE.tar.gz /var/www
scp -P <port> backup-$DATE.tar.gz user@server:/destination/path
rm /var/www/etc-nginx.tar
rm /var/www/full.sql
rm /root/backup-$DATE.tar.gz

The changes are relatively minor. I have since decided to set my nginx configuration to backup. So I just tar it up in to the www/ root, the same as I do with full.sql. The other change is simply moving all the delete commands to the end of the script.

Though I had used SSH key authentication a few times; times have finally made me adopt it as my sole way of connecting to my machines over the internet. It wound up making this script a lot easier to write as it automates the login process in a way that’s not leaving a door wide open. If you decide you want to use this stupid simple script; keep that in mind.

I also originally intended to drop this in cron.daily, but it never worked. I could have debugged what I did wrong or didn’t do…but it was a lot easier to just crontab -e as root.

Site comments disabled. Please use Twitter.