#!/bin/bash
# Backup a database *locally* to /backups/.

DB=$1

# Make our latest backup
ionice -c3 /bin/mysqldump --user=root --add-drop-database $DB | /usr/bin/xz > /backups/$DB-$(date +%F).dump.xz

# link to the latest backup
ln -sf /backups/$DB-$(date +%F).dump.xz /backups/$DB-latest.xz

# Also, delete the backup from a few days ago.
rm -f /backups/$DB-$(date --date="3 days ago" +%F).dump.xz
