LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Scheduling MySQL database backups with date dependent filenames (https://www.linuxquestions.org/questions/linux-general-1/scheduling-mysql-database-backups-with-date-dependent-filenames-406130/)

pepolez 01-21-2006 07:25 AM

Scheduling MySQL database backups with date dependent filenames
 
Just wondering if it is possible to tell a MySQL server to backup files at a set interval but with a different filename each time which reflects the date. I know scheduled backups with the same name are possible (done through webmin, other ways too?), but this isn't what I'm looking for.

For example:

at 1am on January 22, 2006, the backup will be saved to a specified directory with the name 22-1-2006-DBNAME.sql

at 1am on January 23, 2006, the backup will be saved to a specified directory with the name 23-1-2006-DBNAME.sql

etc etc

trickykid 01-21-2006 09:45 AM

Here's a portion of a script I made to place in my /etc/cron.daily directory to do daily backups of my databases..

Code:

#!/bin/bash
#
# System Backup Script.

host=myhost
date=$(date +%F)
filename=$host.$date

cd /backup/mysql
mysqldump -u<username> -p<password> --databases dbname > $filename_dbname.sql
gzip $filename_dbname.sql

exit 0

I actually have different hosts so that's why I also have the host name in it. But that should pretty much do what you want, just change the small amount to customize.


All times are GMT -5. The time now is 07:23 PM.