This gotcha always gets me and when I google it I get nowhere.
Backup all databases:
BACKUP_FILE=`/mnt/backups/all_databases_`date -I`-`echo $RANDOM % 1000 | bc`.sql`
mysqldump -u root -h 127.0.0.1 --all-database > $BACKUP_FILE
Restore a specific database:
RESTORE_FILE=`ls -tr /mnt/backups/*.sql | tail -n 1`
mysql -u root -h 127.0.0.1
drop database db_name;
create database db_name;
exit
mysql -u root -h 127.0.0.1 db_name < $RESTORE_FILE
note: when restoring a database, you may need to use the same DB name as the original
Post a Comment