Spearfoot

Wrapper for rsync for use with Windows datasets on FreeNAS

Jun 8th, 2016
933
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.11 KB | None | 0 0
  1. #!/bin/bash
  2. #######################################################################
  3. # A wrapper for invoking rsync to copy a source dataset to a destination
  4. # dataset with options that are 'known to work' with FreeNAS/FreeBSD
  5. # and Windows datasets. This means we have to avoid the '-p' (preserve
  6. # permissions) option in all of its forms, per bug report 7713:
  7. #
  8. # https://bugs.freenas.org/issues/7713
  9. #
  10. # Command-line parameters:
  11. #   1: Source dataset       R_SRC     (local system)  /mnt/tank/sharename/
  12. #   2: Destination dataset  R_DEST    (local system)  /volume1/sharename
  13. #   3: Log file             R_LOGFILE (local system)  /mnt/tank/sysadmin/log/push-log.log
  14. #
  15. # R_SRC or R_DEST may include user ID and hostname specifier
  16. #
  17. # Example usage, where 'boomer' is a FreeNAS server and 'bertrand' is
  18. # a Synology Diskstation. Note that you should include a trailing slash
  19. # only on the source dataset specifier:
  20. #
  21. # rsync-invoke.sh root@bertrand:/volume1/devtools/ /mnt/tank/devtools /mnt/tank/sysadmin/log/pull-from-bertrand.log
  22. # rsync-invoke.sh /mnt/tank/devtools/ root@bertrand:/volume1/devtools /mnt/tank/sysadmin/log/push-to-bertrand.log
  23. #
  24. # Assumes SSH has been enabled and configured between the source
  25. # and destination hosts.
  26. #
  27. # Invokes rsync with these SSH options to optimize transfer speed:
  28. #
  29. #   "-e ssh -T -c arcfour -o Compression=no -x"
  30. #
  31. # You may need to remove this altogether, or modify the encryption
  32. # specifier (-c arcfour) to use a scheme available on your system.
  33. #
  34. # !!! WARNING !!!
  35. # This script deletes files on the destination that don't exist
  36. # on the source! Edit R_OPTIONS below and remove '--delete-during'
  37. # and '--inplace' if you don't want this behavior!
  38. #
  39. # Tested with:
  40. #   FreeNAS 9.3-STABLE
  41. #   FreeNAS 9.10-STABLE
  42. #   Synology DSM 5.x (as destination only)
  43. #######################################################################
  44.  
  45. if [ $# -ne 3 ]
  46. then
  47.   echo "Error: not enough arguments!"
  48.   echo "Usage is: $0 r_src r_dest r_logfile"
  49.   exit 2
  50. fi
  51.  
  52. R_SRC=$1
  53. R_DEST=$2
  54. R_LOGFILE=$3
  55.  
  56. # Options:
  57. #   -r  recurse into directories
  58. #   -l  copy symlinks as symlinks
  59. #   -t  preserve modification times
  60. #   -g  preserve group
  61. #   -o  preserve owner
  62. #   -D  preserve device and special files
  63. #   -h  human readable progress
  64. #   -v  increase verbosity
  65.  
  66. #   --delete-during   receiver deletes during the transfer
  67. #   --inplace         write updated data directly to destination file
  68. #   --log-file        specify log file
  69.  
  70. R_OPTIONS="-rltgoDhv --delete-during --inplace --log-file="${R_LOGFILE}
  71.  
  72. # Files to exclude:
  73. #   .windows      FreeNAS ACL settings (?)
  74. #   vmware.log    VMware virtual machine log files
  75. #   vmware-*.log
  76. #   @eaDir/       Synology extended attributes (?)
  77. #   @eaDir
  78. #   Thumbs.db     Windows system files
  79.  
  80. R_EXCLUDE="--exclude .windows --exclude vmware.log --exclude vmware-*.log --exclude @eaDir/ --exclude @eaDir --exclude Thumbs.db"
  81.  
  82. echo "$(date) Copy" ${R_SRC} "to" ${R_DEST} >> ${R_LOGFILE}
  83. rsync ${R_OPTIONS} ${R_EXCLUDE} "-e ssh -T -c arcfour -o Compression=no -x" ${R_SRC} ${R_DEST}
  84. echo "$(date) Copy completed" >> ${R_LOGFILE}
  85. exit
Add Comment
Please, Sign In to add comment