Today we need to use a backup website, write a script, back up MySQL and redis data.
#!/bin/Bashbackdir="/home/tan/getll_backup"if[!-d $BACKDIR]; Then mkdir$BACKDIRfi; Backdir_tmp= $BACKDIR"/backup"if[-D $BACKDIR _tmp]; Then EchoTemp directory exists ...Else mkdir$BACKDIR _tmpEchoCreate temp directory successfully ...fiSUFFIX=$(Date+%y%m%d) BackupFileName= $BACKDIR _tmp/Mysql_$suffix.sqlmysqldump-uroot-p0000 getll >$backupFileNameEchoBackup Database Complete ... # with attribute copyCP-a/var/lib/redis/appendonly.aof/var/lib/redis/Dump.rdb $BACKDIR _tmpEchobackup Redis Complete ... # using tar, it's best not to use absolute paths hereEchoto package ... cd $BACKDIR&&Tar-CZVPF Back_$suffix.Tar. GZ backup/# Delete Temp directoryRM-R BackupEchoDelete Temp directory succeededEchoBackup complete
The next thing to do is to do it regularly.
sudo crontab-e edit cron command, write:
0 6 * * * SH ~/getll_auto_backup.sh >>/var/log/getll/cron.log
Where sudo represents the use of root to execute, then ~ represents the/root directory.
This command means to execute the SH ~/getll_auto_backup.sh command at 6 o ' Day, and redirect the output to/var/log/getll/cron.log, specific to the Google cron command.
Linux Data Backup