說明:使用需要 ROOT 權限,需要裝有 xz-utils 套件,
要使用需要修改幾個地方:
09 USER = 這邊改你自己的一般使用者帳號。
10 SAVE_AS = 要先建立好要存放備份檔的地方,
我個人是放 /bak_dir 下,再上傳到雲端空間。
最後是註解圍起來的地方「Backup List」,請自訂你想要備份的檔案、目錄。
vi Backup_data.sh
#!/bin/bash # 2014/06/24 KLin # Backup My data. # parameter setting TIME=`date +"%Y%m%d"` # Use Setting USER=youUsserName SAVE_AS=/bak_dir BAK_DIR=backup_$TIME BAK_TARGET=$SAVE_AS/$BAK_DIR # check account if [ ! `whoami` == root ];then echo "Permision Deny, you're no root." exit 0 fi # check directory if [ -e "$BAK_TARGET.tar.xz" ];then echo "Directory exist!" exit 0 fi # build directory mkdir $BAK_TARGET mkdir -p $BAK_TARGET/root_dir mkdir -p $BAK_TARGET/${USER}_dir ############################################################## ## Backup List # system backup list rsync -av /etc $BAK_TARGET/root_dir # root backup list rsync -av /root/.bashrc $BAK_TARGET/root_dir rsync -av /root/.vimrc $BAK_TARGET/root_dir rsync -av /root/* $BAK_TARGET/root_dir # user backup list rsync -av /home/$USER/.bashrc $BAK_TARGET/${USER}_dir rsync -av /home/$USER/.conkyrc $BAK_TARGET/${USER}_dir rsync -av /home/$USER/.vimrc $BAK_TARGET/${USER}_dir rsync -av /home/$USER/.xinitrc $BAK_TARGET/${USER}_dir rsync -av /home/$USER/.asoundrc $BAK_TARGET/${USER}_dir rsync -av /home/$USER/bin $BAK_TARGET/${USER}_dir rsync -av /home/$USER/images $BAK_TARGET/${USER}_dir rsync -av /home/$USER/Notes $BAK_TARGET/${USER}_dir rsync -av /home/$USER/Other_work $BAK_TARGET/${USER}_dir rsync -av /home/$USER/sdl $BAK_TARGET/${USER}_dir rsync -av /home/$USER/Script $BAK_TARGET/${USER}_dir rsync -av /home/$USER/Eclipse $BAK_TARGET/${USER}_dir rsync -av /home/$USER/Java $BAK_TARGET/${USER}_dir #rsync -av /home/$USER/driver $BAK_TARGET/${USER}_dir ############################################################## # compress cd $SAVE_AS;tar -c --xz -f $BAK_DIR.tar.xz $BAK_DIR # remove dir rm -r $BAK_TARGET # permision change chown $USER:$USER $BAK_TARGET.tar.xz
最後加入可執行權限,放到執行檔目錄下:
chmod a+x Backup_data.sh mv Backup_data.sh /usr/local/bin/
使用方法,直接下 Backup_data.sh 指令。
沒有留言:
張貼留言