Linux-文件备份shell
==========================backup=======================================
#!/bin/bash
DIR="/tmp/test"
BAK="$DIR/backup/"
SRC="$DIR/source/"
TODAY=$(date +"%F %H:%M:%S")
FILELIST="$DIR/filelist.txt"
TIME_FILE="$DIR/time_key"
FULL () {
touch $TIME_FILE
find $SRC -type f > $FILELIST
mkdir -p $BAK/"$TODAY"
tar -T $FILELIST -czf - | tar -xzf - -C $BAK/"$TODAY"
sed -i "s/$/\t$TODAY/" $FILELIST
}
UPDATE () {
touch $TIME_FILE.new
find $SRC -type f -newer $TIME_FILE > $DIR/updatefilelist.txt
mkdir -p $BAK/"$TODAY"
tar -T $DIR/updatefilelist.txt -czf - | tar -xzf - -C $BAK/"$TODAY"
/bin/mv $TIME_FILE.new $TIME_FILE
while read F_NAME
do
STR=$(grep "^$F_NAME\>" $FILELIST)
if [ -z "$STR" ]
then
echo -e "$F_NAME\t$TODAY" >> $FILELIST
else
sed -i "s%$STR%$F_NAME\t$TODAY%" $FILELIST
fi
done < $DIR/updatefilelist.txt
}
case $1 in
full)
FULL;;
update)
UPDATE;;
*)
echo "bash $0 (full|update)";;
esac
#!/bin/bash
DIR="/tmp/test"
BAK="$DIR/backup/"
SRC="$DIR/source/"
TODAY=$(date +"%F %H:%M:%S")
FILELIST="$DIR/filelist.txt"
TIME_FILE="$DIR/time_key"
FULL () {
touch $TIME_FILE
find $SRC -type f > $FILELIST
mkdir -p $BAK/"$TODAY"
tar -T $FILELIST -czf - | tar -xzf - -C $BAK/"$TODAY"
sed -i "s/$/\t$TODAY/" $FILELIST
}
UPDATE () {
touch $TIME_FILE.new
find $SRC -type f -newer $TIME_FILE > $DIR/updatefilelist.txt
mkdir -p $BAK/"$TODAY"
tar -T $DIR/updatefilelist.txt -czf - | tar -xzf - -C $BAK/"$TODAY"
/bin/mv $TIME_FILE.new $TIME_FILE
while read F_NAME
do
STR=$(grep "^$F_NAME\>" $FILELIST)
if [ -z "$STR" ]
then
echo -e "$F_NAME\t$TODAY" >> $FILELIST
else
sed -i "s%$STR%$F_NAME\t$TODAY%" $FILELIST
fi
done < $DIR/updatefilelist.txt
}
case $1 in
full)
FULL;;
update)
UPDATE;;
*)
echo "bash $0 (full|update)";;
esac
本文来自希曼博客-www.ximan.tech,作者:希曼博客,转载请注明原文链接:https://www.cnblogs.com/lihuaichen/p/10128542.html