In Linux, there are many ways to back up the system. In addition to using the backup tool, you can also back up the Linux system through the shell. The following small series will share the shell of the backup Linux system. script.
script is 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 <;Enter Enter Your Backup Files or Directories\ ----- ---------------------------------------\ Example $0 /boot /etc . . . . . . ”
exit
fi
#Determine or 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 “----- ---------------------------------------\ These 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_DIR[@]}`
[ “$CODE” == “0” ]& &echo -e “-----------------------------------------\ These Add_Backup System Files Backup Successfully ! ”
fi
else
if
[ $WEEK -ne “7” ];then
cd $TARGET_DIR /$YEAR/$MONTH/$DAY ;tar -g $TARGET_DIR/snapshot -czvf $FILES `echo ${SOURCE_DIR[@]}`
[ “$CODE” == “0” ] &&echo -e “----------------------------------------- --\ These Add_Backup System Files Backup Successfully ! ”
fi
fi
}
Full_Backup;Add_Backup
The above is how Linux uses a shell script to back up the system. Through the above script, the system can be automatically backed up, but the script may still have some shortcomings, and the optimization can be improved by itself.
NixNote (Nevernotes client) is an Evernote for Linux client that is primarily used
Linux system, when using the virtual machine VirtualBox to install Windows 8.1, prompt 0x000000C4 er
I have been installing LibreOffice on Linux for a while. I need to uninstall LibreOffice for various
When doing Linux command operations, sometimes many directories are searched for, and these director
How to implement ioctl function in Linux system?
CentOS system installation using Subversion method
Linux system how to prevent CC attack
How to deal with the dead loop of user state process under Linux
Linux how to use vi /vim command
Detailed usage of nl commands under Linux
How do Linux systems delete icons on the gnome panel?
How to use dd command in Linux system
How to configure XFS file system for Linux system
After Ubuntu 12.04 restarts, Ubuntu is running in low-graphics mode
Win8 transparent windowing how to set
CF and TGP head iron rider QB wait for you to lead the event website
How Win8 changes the desktop theme
The rookie can also easily manage the system font
Win2003 system running Sysprep error reasons and solutions
How to slap the card? Scorpio card knife game tutorial Raiders
How does Win10 set up a local connection to a metered network?
About Windows 7: Seven things you must know
"Error 1606" appears in Windows 7 installation software
How to solve the problem that the graphics card cannot be accelerated under Windows 2008