사용자 도구

사이트 도구


rsync

rsync

폴더 동기화

rsync -rv --delete {src_ip}:{src_path} {dst_ip}:{dst_path}

ssh를 통한 동기화

os.system(f'''"rsync -rv -e 'ssh -i {key_file} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' {src_ip}:{src_path} {dst_ip}:{dst_path}"''')

rsync를 이용한 백업 스크립트

#!/bin/bash
 
#Website Backup Script
 
#Todays date in ISO-8601 format:
DAY0=`date -I`
 
#Yesterdays date in ISO-8601 format:
DAY1=`date -I -d "1 day ago"`
 
#The source directory:
SRC="{src_user_id}@{src_host}:{src_path}"
 
#The target directory:
TRG="{dst_path}/$DAY0"
 
#The link destination directory:
LNK="{dst_path}/$DAY1"
 
#The rsync options:
OPT="-avh --delete --link-dest=$LNK -e 'ssh -p {port_number}'"
 
#Execute the backup
rsync $OPT $SRC $TRG
 
#29 days ago in ISO-8601 format
DAY29=`date -I -d "29 days ago"`
 
#Delete the backup from 29 days ago, if it exists
if [ -d /backup/website/$DAY29 ]
then
rm /backup/website/$DAY29
fi

cron에 등록

  sudo ln -s {backup_script} /etc/cron.daily/{backup_script}

- http://webgnuru.com/linux/rsync_incremental.php - http://www.howtogeek.com/135533/how-to-use-rsync-to-backup-your-data-on-linux/

rsync.txt · 마지막으로 수정됨: 2024/03/23 02:38 저자 127.0.0.1