archive with date option

This commit is contained in:
Pavel Kuleshov 2023-03-18 10:33:25 +08:00
parent a9aba2cdf4
commit 418460f5cc

View File

@ -16,20 +16,33 @@ mode='archive'
delete_archive=true
#delete_archive=false
archive_with_date=true
#archive_with_date=false
if [ "$mode" == "files" ]; then
rsync -a --exclude-from=$exclude_file --password-file=$password_file $source $user@$ip::$destination
else
mkdir -p $archive_dir
for dir in $source
do
archive_name=$(date +"%Y%m%d")-$(echo $dir | tr '/' '_').tar.gz
if [ "$archive_with_date" = true ]; then
today=$(date +"%Y%m%d")
archive_dir="$archive_dir/$today"
mkdir -p $archive_dir
fi
for dir in $source; do
if [ "$archive_with_date" = true ]; then
archive_name=$(echo $dir | tr '/' '_').tar.gz
tar -czf $archive_dir/$archive_name $dir
else
archive_name=$(basename $dir).tar.gz
tar -czf $archive_dir/$(date +"%Y%m%d")-$archive_name $dir
fi
done
rsync -a --exclude-from=$exclude_file --password-file=$password_file $archive_dir/* $user@$ip::$destination
rsync -a --exclude-from=$exclude_file --password-file=$password_file --relative $archive_dir/ $user@$ip::$destination
if [ $? -eq 0 ] && [ "$delete_archive" = true ]; then
rm -f $archive_dir/*
rm -rf $archive_dir/*
fi
fi