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