#!/bin/bash backplace="_backup" if [ ! -d $backplace ] ; then mkdir $backplace fi name="$1""_bak_""`date +%Y%m%d`""_""`date +%H%M%S`" cp $1 "$backplace/$name"
#!/bin/bash SRC="/home/yan/workdata" DST1="/home/yan/disk1backup" DST2="/dev/disk2backup" FILE1="worknewdata.tar" FILE2="work2cddata.tar" FILE3="work3rddata.tar" if [ ! -d $SRC ];then echo "no data found!" elif [ ! -w $DST1 -a -w $DST2 ];then echo "device error,please check the devices" else cd $DST1 if [ -f $FILE3 ];then rm $FILE3 fi if [ -f $FILE2 ];then mv $FILE2 $FILE3 fi if [ -f $FILE1 ];then mv $FILE1 $FILE2 fi if [ -f $FILE1 ];then rm $FILE1 fi cd $SRC cd .. tar -cf $FILE1 "workdata" mv $FILE1 $DST1/ cd $DST2 if [ -f $FILE3 ];then rm $FILE3 fi if [ -f $FILE2 ];then mv $FILE2 $FILE3 fi if [ -f $FILE1 ];then mv $FILE1 $FILE2 fi if [ -f $FILE1 ];then rm $FILE1 fi cp $DST1/$FILE1 $DST2/ fi echo "backup data done!"