Linux Data Backup

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.