From 0a5f0a27eed82c8a7e2331c2f35ba27e58c41f6b Mon Sep 17 00:00:00 2001 From: 3err0 Date: Fri, 10 Mar 2023 07:43:56 +0800 Subject: [PATCH] archive mode --- rsync_backup.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/rsync_backup.sh b/rsync_backup.sh index 2698430..05b2cbf 100644 --- a/rsync_backup.sh +++ b/rsync_backup.sh @@ -8,5 +8,25 @@ user='user' ip='ip' source='/opt /var/www' destination='data/' +archive_dir='archives/' -rsync -a --exclude-from=$exclude_file --password-file=$password_file $source $user@$ip::$destination \ No newline at end of file +mode='archive' +#mode='files' + +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 + tar -czf $archive_dir/$archive_name $dir + done + + rsync -a --exclude-from=$exclude_file --password-file=$password_file $archive_dir/* $user@$ip::$destination + + if [ $? -eq 0 ]; then + rm -f $archive_dir/* + fi +fi