Compare commits
2 Commits
a9aba2cdf4
...
4dae05ba2c
Author | SHA1 | Date | |
---|---|---|---|
4dae05ba2c | |||
418460f5cc |
@ -16,20 +16,39 @@ mode='archive'
|
|||||||
delete_archive=true
|
delete_archive=true
|
||||||
#delete_archive=false
|
#delete_archive=false
|
||||||
|
|
||||||
|
archive_with_date=true
|
||||||
|
#archive_with_date=false
|
||||||
|
|
||||||
|
if ! which rsync >/dev/null 2>&1; then
|
||||||
|
echo "rsync is not installed. Installing..."
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y rsync
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$mode" == "files" ]; then
|
if [ "$mode" == "files" ]; then
|
||||||
rsync -a --exclude-from=$exclude_file --password-file=$password_file $source $user@$ip::$destination
|
rsync -a --exclude-from=$exclude_file --password-file=$password_file $source $user@$ip::$destination
|
||||||
else
|
else
|
||||||
mkdir -p $archive_dir
|
mkdir -p $archive_dir
|
||||||
|
|
||||||
for dir in $source
|
if [ "$archive_with_date" = true ]; then
|
||||||
do
|
today=$(date +"%Y%m%d")
|
||||||
archive_name=$(date +"%Y%m%d")-$(echo $dir | tr '/' '_').tar.gz
|
archive_dir="$archive_dir/$today"
|
||||||
tar -czf $archive_dir/$archive_name $dir
|
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
|
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
|
if [ $? -eq 0 ] && [ "$delete_archive" = true ]; then
|
||||||
rm -f $archive_dir/*
|
rm -rf $archive_dir/*
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
Loading…
Reference in New Issue
Block a user