Use bash scripts in Linux--regularly and automatically back up database important files

Source: Internet
Author: User

1. First write your own bash script, give it executable permissions, the code is as follows:

[Git_backup.sh]

1#!/bin/Bash2Code_dir="/home/slamgit/code"3Bak_code_dir="/media/ubuntu/kingston/code"4 functionCode_backup () {5      forElementinch`ls$code _dir '6      Do  7dir_respo= $code _dir"/"$element8git clone $dir _respo $bak _code_dir"/"$element9      DoneTen } One  A  -  while : -  Do theCurrent_date="' Date +%c '"  -     Echo$current _date -     if Echo$current _date |grep "23:59 59 sec"; Then -         Echo "Start Code Backup" +         if ls/media/ubuntu/kingston; Then -             RM/media/ubuntu/kingston/code/*-RF + Code_backup A echo "EXE code Backup": $current _date >>/media/ubuntu/kingston/backup.log at fi - fi -  Done

Two variables are defined first, at a glance to back up the data in the/home/slamgit/code to /media/ubuntu/kingston/code.

A function is then defined to perform the backup operation, iterate through all the data files in the data directory, and perform the backup operation separately.

Finally, the main loop, the loop detects whether the current time is the point at which data needs to be backed up, deletes the old backup data under the backup directory at the time the condition is met, invokes the backup execution function, and writes the backup operation to the log.

2. Set the boot-up script

In the/etc/rc.local file, the statement exit 0 is preceded by a line./home/ubuntu/git_backup.sh

Reboot the system and the setup is complete.

Use bash scripts in Linux--regularly and automatically back up database important files

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.