jr_rsync_newer_sh
**Это старая версия документа!**
Синхронизация последних файлов
- jr_rsync_newer.sh
#!/bin/bash
##########################################
## VARS
##########################################
LIST_FILE='/tmp/rsync.lst'; # Temporary list of files, that must be synced
PERIOD=365; # Number of days that must be synced
SRC_DIR='/var/spool/asterisk/monitor';
DST_DIR='/home/listener';
##########################################
## MAIN
##########################################
find ${SRC_DIR} -mtime -${PERIOD} -type f > ${LIST_FILE}; # Check ${SRC_DIR} for files newer than ${PERIOD} days
# and put the list into ${LIST_FILE}
sed -i -e "s|^${SRC_DIR}/||g" ${LIST_FILE}; # Cut ${SRC_DIR} from every string of ${LIST_FILE}
/usr/bin/rsync -qua --files-from=${LIST_FILE} ${SRC_DIR} ${DST_DIR}; # Rsync files
/bin/chown -R listener:listener /home/listener; # Fix permissions
find ${DST_DIR} -mtime +$(( ${PERIOD} + 1 )) -type f -exec rm '{}' ';'; # Delete old files from ${DST_DIR}
rm ${LIST_FILE}; # Remove ${LIST_FILE}
jr_rsync_newer_sh.1460971637.txt.gz · Последнее изменение: 2016/04/18 12:27 (внешнее изменение)