Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #######################################################################
- # A wrapper for invoking rsync to copy a source dataset to a destination
- # dataset with options that are 'known to work' with FreeNAS/FreeBSD
- # and Windows datasets. This means we have to avoid the '-p' (preserve
- # permissions) option in all of its forms, per bug report 7713:
- #
- # https://bugs.freenas.org/issues/7713
- #
- # Command-line parameters:
- # 1: Source dataset R_SRC (local system) /mnt/tank/sharename/
- # 2: Destination dataset R_DEST (local system) /volume1/sharename
- # 3: Log file R_LOGFILE (local system) /mnt/tank/sysadmin/log/push-log.log
- #
- # R_SRC or R_DEST may include user ID and hostname specifier
- #
- # Example usage, where 'boomer' is a FreeNAS server and 'bertrand' is
- # a Synology Diskstation. Note that you should include a trailing slash
- # only on the source dataset specifier:
- #
- # rsync-invoke.sh root@bertrand:/volume1/devtools/ /mnt/tank/devtools /mnt/tank/sysadmin/log/pull-from-bertrand.log
- # rsync-invoke.sh /mnt/tank/devtools/ root@bertrand:/volume1/devtools /mnt/tank/sysadmin/log/push-to-bertrand.log
- #
- # Assumes SSH has been enabled and configured between the source
- # and destination hosts.
- #
- # Invokes rsync with these SSH options to optimize transfer speed:
- #
- # "-e ssh -T -c arcfour -o Compression=no -x"
- #
- # You may need to remove this altogether, or modify the encryption
- # specifier (-c arcfour) to use a scheme available on your system.
- #
- # !!! WARNING !!!
- # This script deletes files on the destination that don't exist
- # on the source! Edit R_OPTIONS below and remove '--delete-during'
- # and '--inplace' if you don't want this behavior!
- #
- # Tested with:
- # FreeNAS 9.3-STABLE
- # FreeNAS 9.10-STABLE
- # Synology DSM 5.x (as destination only)
- #######################################################################
- if [ $# -ne 3 ]
- then
- echo "Error: not enough arguments!"
- echo "Usage is: $0 r_src r_dest r_logfile"
- exit 2
- fi
- R_SRC=$1
- R_DEST=$2
- R_LOGFILE=$3
- # Options:
- # -r recurse into directories
- # -l copy symlinks as symlinks
- # -t preserve modification times
- # -g preserve group
- # -o preserve owner
- # -D preserve device and special files
- # -h human readable progress
- # -v increase verbosity
- # --delete-during receiver deletes during the transfer
- # --inplace write updated data directly to destination file
- # --log-file specify log file
- R_OPTIONS="-rltgoDhv --delete-during --inplace --log-file="${R_LOGFILE}
- # Files to exclude:
- # .windows FreeNAS ACL settings (?)
- # vmware.log VMware virtual machine log files
- # vmware-*.log
- # @eaDir/ Synology extended attributes (?)
- # @eaDir
- # Thumbs.db Windows system files
- R_EXCLUDE="--exclude .windows --exclude vmware.log --exclude vmware-*.log --exclude @eaDir/ --exclude @eaDir --exclude Thumbs.db"
- echo "$(date) Copy" ${R_SRC} "to" ${R_DEST} >> ${R_LOGFILE}
- rsync ${R_OPTIONS} ${R_EXCLUDE} "-e ssh -T -c arcfour -o Compression=no -x" ${R_SRC} ${R_DEST}
- echo "$(date) Copy completed" >> ${R_LOGFILE}
- exit
Add Comment
Please, Sign In to add comment