Shell script automatically backs up Linux systems

Source: Internet
Author: User

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

Related Article

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.