简体   繁体   中英

how to take phpmyadmin(mysql) backup database cron with date and time

每天凌晨2:30如何备份服务器数据库PHPMYADMIN(MYSQL)以及带时间戳的zip文件。请提供帮助。

Since you want to make a cron you probably want to use mysqldump command.

mysqldump -u database_user -pdatabase-password database_name | gzip -9 > /path/to/backup/directory/database-data/$(date +%Y-%m-%d-%H.%M.%S).sql.gz

Your cron will look like this:

30 2 * * * mysqldump -u database_user -pdatabase-password database_name | gzip -9  /path/to/backup/directory/database-data/$(date +%Y-%m-%d-%H.%M.%S).sql.gz

In some systems like RHEL you might need to escape the characters from the date expression. https://unix.stackexchange.com/questions/8584/using-the-system-date-time-in-a-cron-script

add a \\ before each %. (\\%Y-\\%m-\\%d-\\%H.\\%M.\\%S)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM