Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Automatische Sicherung der MySQL-Datenbank auf dem Linux-Server

Antworten :Ein Cron

Beschreibung :

Versuchen Sie, eine Datei something.sh damit zu erstellen:

 #!/bin/sh
 mysqldump -u root -p pwd --opt db1.sql > /respaldosql/db1.sql
 mysqldump -u root -p pwd --opt db2.sql > /respaldosql/db2.sql
 cd /home/youuser/backupsql/
 tar -zcvf backupsql_$(date +%d%m%y).tgz *.sql
 find -name '*.tgz' -type f -mtime +2 -exec rm -f {} \;

Geben Sie der Datei die entsprechende Berechtigung

 chmod 700 mysqlrespaldo.sh

oder

 sudo chmod 700 something.sh

und erstellen Sie dann einen Cron mit

 crontab -e

Einstellung wie

 **0 1 * * *** /home/youruser/coolscripts/something.sh

Denken Sie daran, dass die Zahlen oder '*'-Zeichen diese Struktur haben: