Today, write an incremental backup system file using shell scripts, and review the shell script related commands, which can be used to back up different files or folders for full backups and incremental backups, depending on your needs. Directly on the script as follows:
#!/bin/sh #Automatic Backup Linux System Files #Author wugk 2013-11-22 #Define Variable source_dir= ($*) target_dir=/ Data/backup/year= ' Date +%y ' month= ' date +%m ' day= ' date +%d ' week= ' date +%u ' files=system_backup.tgz code=$? If [-z] $* "];then echo-e" please Enter Your Backup Files or directories\n---------------------------------------- ----\nexample $0/boot/etc ... "Exitfi#determine Whether the Target Directory Exists if [!-D $TARGET _dir/$YEAR /$MONTH/$DAY];then mkdir-p $TARGET _dir/$YEAR/$MONTH/$DAY echo "This $TARGET _dir is Created successfully!" Fi#exec full_backup Function Command full_backup () {if ["$WEEK"-eq "7"];then RM-RF $TARGET _dir/snapshot CD $ target_dir/$YEAR/$MONTH/$DAY; tar-g $TARGET _dir/snapshot-czvf $FILES ' echo ${source_dir[@]} ' ["$CODE" = = "0"]& &echo-e "--------------------------------------------\nthese full_backup System Files Backup successfully!" FI} #Perform incremental BACKUP Function Command add_Backup () {CD $TARGET _dir/$YEAR/$MONTH/$DAY; if [-F $TARGET _dir/$YEAR/$MONTH/$DAY/$FILES];then read-p "These $FILES already Exists, overwrite confirmation yes or no? : "Sure if [$SURE = =" No "-o $SURE = =" N "];then sleep 1; exit 0 fi#add_backup Files System if [$ Week-ne "7"];then CD $TARGET _dir/$YEAR/$MONTH/$DAY; tar-g $TARGET _dir/snapshot-czvf $$_$files ' echo ${source_di r[@]} ' ["$CODE" = = "0"]&&echo-e "-----------------------------------------\nthese add_backup System Fi Les Backup successfully! " Fielse if [$WEEK-ne "7"];then CD $TARGET _dir/$YEAR/$MONTH/$DAY; tar-g $TARGET _dir/snapshot-czvf $FILES ' E Cho ${source_dir[@]} ' ["$CODE" = = "0"]&&echo-e "-------------------------------------------\nthese add_b Ackup System Files Backup successfully! " Fifi} Full_backup; Add_backup
Shell script automatically backs up Linux systems