1) Seeing if people have suggestions for additional things I should do or if I missed anything.
2) Helping people looking to script backups.
From what I can tell, all I need to backup is the database. Note that my deployment scripts and config files are in version control (where they belong). So to back up the database I have the following two files:
/etc/cron.d/mysql:
Code: Select all
50 4 * * * root /usr/local/sbin/mysql-backup.sh expire
cat usr/local/sbin/mysql-backup.sh
Code: Select all
#!/bin/bash
TS=$(date +"%Y-%m-%d_%H:%M:%S")
BACKUP_DIR=/backups
BACKUP_STEM="ttrss.$TS.mysqldump"
if [[ ! -d "$BACKUP_DIR" ]]; then
mkdir -p "$BACKUP_DIR"
fi
mysqldump --single-transaction ttrss > "$BACKUP_DIR/,$BACKUP_STEM"
nice lzip "$BACKUP_DIR/,$BACKUP_STEM"
mv "$BACKUP_DIR/,$BACKUP_STEM".lz "$BACKUP_DIR/$BACKUP_STEM".lz
if [[ "$1" == "expire" ]]; then
find /backups -mtime +7 -print0 | xargs -0 rm -f
fi
I find this compresses very well and doesn't put a lot of load on the system. It keeps the last 7 days of backups just in case there's an issue with a rollback. Traditionally on Unix systems a file that begins with a , is a temporary file and the command I use to rsync files excludes such files - which is why the backup file starts with a , until it's done.
For DB auth, I have a /root/.my.cnf file with the auth credentials I need.