【linux备份】Linux备份和恢复方法|tar打包排除某个目录
tar zcvf fd.tar.gz * --exclude=file1 --exclude=dir1
注意:
1、--exclude=file1 而不是 --exclude file1
2、要排除一个目录是--exclude=dir1而不是--exclude=dir1/
也可以在父目录打包
tar zcvf fd.tar.gz pardir --exclude=pardir/file1 --exclude=pardir/dir1
备份脚本:
cat<< EOF
color 1e
echo ============================================== echo Centos备份与恢复脚本
echo ============================================== echo 1. 备份centos7
echo 2. 恢复centos7系统
EOF
function Backup() {
cd /
tarcvpzf backup.tgz / --exclude=/proc
--exclude=/mnt --exclude=/sys --exclude=/data
}
function Restore() {
cd /
tarxvpfz backup.tgz -C /
}
functionChiose() {
cd /
read -p "Please enter your chiose:" chiose
if [ "$chiose" == 1 ]
then
Backup
elif [ "$chiose" == 2 ]
then
if [ ! -e backup.tgz ]
then
echo "Please check your backup file !"
Chiose
else
Restore
fi
else
Chiose
fi
}
--exclude=/lost+found --exclude=/backup.tgz
Chiose
来源:http://wk.baidu.com/view/475a12c452ea551811a6870a?pn=1&pu=