Automatically back up the database using mysqldump timing
The code is as follows |
Copy Code |
[Root@www www]# VI backup-db.sh #!/bin/sh /bin/nice-n 19/usr/bin/mysqldump-u vpsmysql--password=vpsmysqlpassword mysqlname-c | /bin/nice-n 19/bin/gzip-9 > /web/www/db-backup/vps-$ (date ' +%y%m%d '). sql.gz rm-rf/web/www/db-backup/vps-$ (Date +%y%m%d-d "7 days Ago"). sql.gz# the above statement deletes a 7-day backup
|
The above script-U followed the database user name, –password the database password, followed by the database name, followed by the/web/www/db-backup/is the backup directory.
Add a timed execution task
The code is as follows |
Copy Code |
[Root@www ~]# Crontab-e * * */web/www/backup-db.sh |
Daily 23:59 chapters automatically back up the database, and the resulting database compression is named by date
The above backup of the information, backed up quickly to download the backup to the local, after all, the backup data are in the VPS, not around