hackbyte

safe-rsync-foo-(local)v20170415T0540UTC.sh

Apr 15th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 17.28 KB | None | 0 0
  1. #!/bin/bash
  2. export MY_WHICH=`which which`
  3. export MY_RSYNC_BIN=`${MY_WHICH} rsync`
  4. export MY_FSCK_GRACE_TIME="10" ## Grace time in seconds as in having `sleep 1s` running in loop for every count...
  5. export MY_FSCK_LONG_NAME="$0"
  6. export MY_FSCK_SHORT_NAME=`basename ${MY_FSCK_LONG_NAME}`
  7. export MY_FSCK_FUCKUP_BASENAME="safe-rsync-testing-"
  8. export MY_FSCK_FUCKUP_TIMESTAMP=`date "+%Y%m%dT%H%M%S.%N_%Z"`
  9. export MY_FSCK_FUCKUP_PWD="/root/"
  10. export MY_FSCK_FUCKUP_NAME="${MY_FSCK_FUCKUP_PWD}${MY_FSCK_FUCKUP_BASENAM}${MY_FSCK_FUCKUP_TIMESTAMP}"
  11. export MY_FSCK_LOG_FILE="${MY_FSCK_FUCKUP_NAME}.log"
  12. export MY_FSCK_BATCH_FILE="${MY_FSCK_FUCKUP_NAME}_batch"
  13.  
  14. ################################################################################
  15. ## Some Stuff
  16.  
  17. # The CVSIGNORE environment variable supplements any ignore patterns in .cvsignore files. See the --cvs-exclude option for more details.
  18. unset CVSIGNORE
  19.  
  20. # Specify a default --iconv setting using this environment variable. (First supported in 3.0.0.)
  21. unset RSYNC_ICONV
  22.  
  23. # Specify  a  non-zero  numeric  value if you want the --protect-args option to be enabled by default, or a zero value to make sure that it is disabled by default. (First supported in 3.1.0.)
  24. unset RSYNC_PROTECT_ARGS
  25. export RSYNC_PROTECT_ARGS=1
  26.  
  27. # The RSYNC_RSH environment variable allows you to override the default shell used as the transport for rsync.  Command line options are permitted after  the  command name, just as in the -e option.
  28. unset RSYNC_RSH
  29.  
  30. # The RSYNC_PROXY environment variable allows you to redirect your rsync client to use a web proxy when connecting to a rsync daemon. You should set RSYNC_PROXY to a hostname:port pair.
  31. unset RSYNC_PROXY
  32.  
  33. # Setting RSYNC_PASSWORD to the required password allows you to run authenticated rsync connections to an rsync daemon without user intervention.  Note  that  this does not supply a password to a remote shell transport such as ssh; to learn how to do that, consult the remote shell?s documentation.
  34. unset RSYNC_PASSWORD
  35.  
  36. echo "                \$0 = $0"
  37. echo "                \$* = $*"
  38. echo "                   ($0 $*)"
  39. echo "                \$1 = $1"
  40. echo "                \$2 = $2"
  41. echo "                \$3 = $3"
  42. echo "                \$4 = $4"
  43. echo "                \$5 = $5"
  44.  
  45. echo "MY_FSCK_FUCKUP     = $MY_FSCK_FUCKUP_testing"
  46. echo "MY_FSCK_LONG_NAME  = ${MY_FSCK_LONG_NAME}"
  47. echo "MY_FSCK_SHORT_NAME = ${MY_FSCK_SHORT_NAME}"
  48.  
  49. echo "MY_WHICH           = ${MY_WHICH}"
  50. echo "MY_RSYNC_BIN       = ${MY_RSYNC_BIN}"
  51.  
  52.  
  53.   OUR_RSYNC_OPTS_STRING=""
  54. # OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}"
  55.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--verbose "
  56.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--human-readable "
  57.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--progress "
  58.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--stats "
  59.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--itemize-changes "
  60.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--one-file-system "
  61.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--checksum "
  62.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--archive "
  63.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--recursive "
  64.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--perms "
  65.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--executability "
  66.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--links "
  67.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--copy-unsafe-links "
  68.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--times "
  69.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--group "
  70.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--owner "
  71.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--sparse "
  72.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--partial "
  73.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--acls "
  74.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--xattrs "
  75.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--hard-links "
  76.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--protect-args "
  77.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--compress-level=0 "
  78.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--no-compress "
  79.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--super "
  80.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--specials "
  81.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--preallocate "
  82.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--copy-dirlinks "
  83.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--usermap=38242:1975 "
  84.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--groupmap=38242:1975 "
  85.   OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--outbuf=block "
  86. ##OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--timeout=10 "
  87. ##OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--dry-run "
  88. ##OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--log-file-format=FMT "
  89. ##OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--log-file-format=\"%Y%m%dT%H%M%S.%N_%Z\" "
  90. # OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--log-file=${MY_FSCK_LOG_FILE} "
  91. # OUR_RSYNC_OPTS_STRING="${OUR_RSYNC_OPTS_STRING}--only-write-batch=${MY_FSCK_BATCH_FILE} "
  92.  
  93. OUR_FSCK_FINAL_RSYNC_COMMAND="${MY_RSYNC_BIN} ${OUR_RSYNC_OPTS_STRING}${1} ${2}"
  94.  
  95. echo -e  "\n\n"
  96. echo     "###### DANGER ############ DANGER ############ DANGER ############ DANGER ######"
  97. echo     "#"
  98. echo     "#"
  99. echo     "# executing the following command in ${MY_FSCK_GRACE_TIME} seconds:"
  100. echo     "#"
  101. echo     "#"
  102. echo     ""
  103. echo     "SUPERDATE = %Y%m%dT%H%M%S.%N_%Z"
  104. echo     "SUPERDATE = `date +%Y%m%dT%H%M%S.%N_%Z` (\`date %Y%m%dT%H%M%S.%N_%Z\`)"
  105. echo     ""
  106. echo     "${OUR_FSCK_FINAL_RSYNC_COMMAND}"
  107. echo     ""
  108. echo     ""
  109. echo     "#"
  110. echo     "#"
  111. echo     "# delay for..."
  112.  
  113. echo -en "${MY_FSCK_GRACE_TIME}... "
  114.  
  115. for MY_FSCK_GRACE_TIME_COUNTER in `seq 1 ${MY_FSCK_GRACE_TIME}` ; do
  116.   sleep 1s
  117.   MY_FSCK_GRACE_TIME_COUNTER_REMAINING=$((${MY_FSCK_GRACE_TIME}-${MY_FSCK_GRACE_TIME_COUNTER}))
  118.   echo -en "\n\n${MY_FSCK_GRACE_TIME_COUNTER_REMAINING}... "
  119. done
  120.  
  121. #echo "you got lucky!!!"
  122. echo "let's go!"
  123.  
  124. $OUR_FSCK_FINAL_RSYNC_COMMAND
  125.  
  126. exit 254
  127.  
  128. ################################################################################
  129. ##       --remove-source-files
  130. ##              This tells rsync to remove from the sending side the files (meaning non-directories) that are a part of the  transfer  and
  131. ##              have been successfully duplicated on the receiving side.
  132. ##       -B, --block-size=BLOCKSIZE
  133. ##              This  forces  the  block size used in rsync?s delta-transfer algorithm to a fixed value.  It is normally selected based on
  134. ##              the size of each file being updated.  See the technical report for details.
  135.  
  136. ################################################################################
  137. ##       --list-only
  138. ##              This option will cause the source files to be listed instead of transferred.  This option is inferred if there is a single
  139. ##              source  arg and no destination specified, so its main uses are: (1) to turn a copy command that includes a destination arg
  140. ##              into a file-listing command, or (2) to be able to specify more than one source arg (note: be sure to include the  destina?
  141. ##              tion).   Caution:  keep  in  mind that a source arg with a wild-card is expanded by the shell into multiple args, so it is
  142. ##              never safe to try to list such an arg without using this option.  For example:
  143. ##
  144. ##                  rsync -av --list-only foo* dest/
  145. ##
  146. ##              Starting with rsync 3.1.0, the sizes output by --list-only are affected by the --human-readable option.  By  default  they
  147. ##              will  contain digit separators, but higher levels of readability will output the sizes with unit suffixes.  Note also that
  148. ##              the column width for the size output has increased from 11 to 14 characters for all human-readable levels.  Use --no-h  if
  149. ##              you want just digits in the sizes, and the old column width of 11 characters.
  150. ##
  151. ##              Compatibility  note:   when  requesting  a  remote  listing of files from an rsync that is version 2.6.3 or older, you may
  152. ##              encounter an error if you ask for a non-recursive listing.  This is because a file listing implies the --dirs  option  w/o
  153. ##              --recursive,  and older rsyncs don?t have that option.  To avoid this problem, either specify the --no-dirs option (if you
  154. ##              don?t need to expand a directory?s content),  or  turn  on  recursion  and  exclude  the  content  of  subdirectories:  -r
  155. ##              --exclude='/*/*'.
  156. ##
  157. ##       --bwlimit=RATE
  158. ##              This option allows you to specify the maximum transfer rate for the data sent over the socket, specified in units per sec?
  159. ##              ond.  The RATE value can be suffixed with a string to indicate a size multiplier, and may  be  a  fractional  value  (e.g.
  160. ##              "--bwlimit=1.5m").   If no suffix is specified, the value will be assumed to be in units of 1024 bytes (as if "K" or "KiB"
  161. ##              had been appended).  See the --max-size option for a description of all the available suffixes. A value of zero  specifies
  162. ##              no limit.
  163. ##
  164. ##              For  backward-compatibility  reasons, the rate limit will be rounded to the nearest KiB unit, so no rate smaller than 1024
  165. ##              bytes per second is possible.
  166. ##
  167. ##              Rsync writes data over the socket in blocks, and this option both limits the size of the blocks  that  rsync  writes,  and
  168. ##              tries  to  keep  the average transfer rate at the requested limit.  Some "burstiness" may be seen where rsync writes out a
  169. ##              block of data and then sleeps to bring the average rate into compliance.
  170. ##
  171. ##              Due to the internal buffering of data, the --progress option may not be an accurate reflection on how  fast  the  data  is
  172. ##              being  sent.   This is because some files can show up as being rapidly sent when the data is quickly buffered, while other
  173. ##              can show up as very slow when the flushing of the output buffer occurs.  This may be fixed in a future version.
  174. ##
  175. ##       --write-batch=FILE
  176. ##              Record a file that can later be applied to another identical destination with --read-batch. See the "BATCH  MODE"  section
  177. ##              for details, and also the --only-write-batch option.
  178. ##
  179. ##       --only-write-batch=FILE
  180. ##              Works  like  --write-batch,  except that no updates are made on the destination system when creating the batch.  This lets
  181. ##              you transport the changes to the destination system via some other means and then apply the changes via --read-batch.
  182. ##
  183. ##              Note that you can feel free to write the batch directly to some portable media: if this media fills to capacity before the
  184. ##              end  of  the transfer, you can just apply that partial transfer to the destination and repeat the whole process to get the
  185. ##              rest of the changes (as long as you don?t mind a partially updated destination system while the multi-update cycle is hap?
  186. ##              pening).
  187. ##
  188. ##              Also  note that you only save bandwidth when pushing changes to a remote system because this allows the batched data to be
  189. ##              diverted from the sender into the batch file without having to flow over the wire  to  the  receiver  (when  pulling,  the
  190. ##              sender is remote, and thus can?t write the batch).
  191. ##
  192. ##       --read-batch=FILE
  193. ##              Apply  all of the changes stored in FILE, a file previously generated by --write-batch.  If FILE is -, the batch data will
  194. ##              be read from standard input.  See the "BATCH MODE" section for details.
  195. ##
  196. ##
  197. ##       --checksum-seed=NUM
  198. ##              Set  the checksum seed to the integer NUM.  This 4 byte checksum seed is included in each block and MD4 file checksum cal?
  199. ##              culation (the more modern MD5 file checksums don?t use a seed).  By default the checksum seed is generated by  the  server
  200. ##              and  defaults  to  the current time() .  This option is used to set a specific checksum seed, which is useful for applica?
  201. ##              tions that want repeatable block checksums, or in the case where the user wants a more random checksum seed.  Setting  NUM
  202. ##              to 0 causes rsync to use the default of time() for checksum seed.
  203. ##
  204.  
  205. ################################################################################
  206. ##       --out-format=FORMAT
  207. ##              This  allows you to specify exactly what the rsync client outputs to the user on a per-update basis.  The format is a text
  208. ##              string containing embedded single-character escape sequences prefixed with a percent (%) character.   A default format  of
  209. ##              "%n%L" is assumed if either --info=name or -v is specified (this tells you just the name of the file and, if the item is a
  210. ##              link, where it points).  For a full list of  the  possible  escape  characters,  see  the  "log  format"  setting  in  the
  211. ##              rsyncd.conf manpage.
  212. ##
  213. ##              Specifying  the  --out-format  option  implies  the  --info=name option, which will mention each file, dir, etc. that gets
  214. ##              updated in a significant way (a transferred file, a recreated symlink/device, or a touched directory).   In  addition,  if
  215. ##              the  itemize-changes escape (%i) is included in the string (e.g. if the --itemize-changes option was used), the logging of
  216. ##              names increases to mention any item that is changed in any way (as long as the receiving side is at least 2.6.4).  See the
  217. ##              --itemize-changes option for a description of the output of "%i".
  218. ##
  219. ##              Rsync  will  output  the  out-format  string  prior  to  a file?s transfer unless one of the transfer-statistic escapes is
  220. ##              requested, in which case the logging is done at the end of the file?s transfer.  When this late logging is in  effect  and
  221. ##              --progress is also specified, rsync will also output the name of the file being transferred prior to its progress informa?
  222. ##              tion (followed, of course, by the out-format output).
  223. ##
  224.  
  225. ################################################################################
  226. ##
  227. ##       --log-file-format=FORMAT
  228. ##              This  allows you to specify exactly what per-update logging is put into the file specified by the --log-file option (which
  229. ##              must also be specified for this option to have any effect).  If you specify an empty string, updated  files  will  not  be
  230. ##              mentioned  in the log file.  For a list of the possible escape characters, see the "log format" setting in the rsyncd.conf
  231. ##              manpage.
  232. ##
  233. ##              The default FORMAT used if --log-file is specified and this option is not is ?%i %n%L?.
  234. ##
  235.  
  236.  
  237. ################################################################################
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244. ################################################################################
  245. # oldoptsfu -valES --no-compress scSrix
  246. ##        -a, --archive               archive mode; equals -rlptgoD (no -H,-A,-X)
  247. ##          -r, --recursive             recurse into directories
  248. ##          -l, --links                 copy symlinks as symlinks
  249. ##          -p, --perms                 preserve permissions
  250. ##          -t, --times                 preserve modification times
  251. ##          -g, --group                 preserve group
  252. ##          -o, --owner                 preserve owner (super-user only)
  253. ##
  254. ##        -v, --verbose               increase verbosity
  255. ##        -A, --acls                  preserve ACLs (implies -p)
  256. ##        -H, --hard-links            preserve hard links
  257. ##        -s, --protect-args          no space-splitting; wildcard chars only
  258. ##        -S, --sparse                handle sparse files efficiently
  259. ##        -h, --human-readable        output numbers in a human-readable format
  260. ##            --progress              show progress during transfer
  261. ##            --stats                 give some file-transfer stats
  262. ##        -x, --one-file-system       don_t cross filesystem boundaries
  263. ##        -c, --checksum              skip based on checksum, not mod-time & size
  264. ##            --copy-unsafe-links     only "unsafe" symlinks are transformed
  265. ##        -E, --executability         preserve executability
  266. ##            --partial               keep partially transferred files
  267. ##        -i, --itemize-changes       output a change-summary for all updates
  268. ##
  269. ##            --log-file=FILE         log what we_re doing to the specified FILE
  270. ##            --log-file-format=FMT   log updates using the specified FMT
  271. ##
  272. ##       --inplace ## potentially dangerous, only for initial copy
  273. ##            --numeric-ids           don_t map uid/gid values by user/group name
  274. ##            --usermap=STRING        custom username mapping
  275. ##            --groupmap=STRING       custom groupname mapping
  276. ##            --chown=USER:GROUP      simple username/groupname mapping
  277. ##
  278. ##  --no-compress
  279. ##
  280. ##        -z, --compress              compress file data during the transfer
  281. ##            --compress-level=NUM    explicitly set compression level
  282. ##            --skip-compress=LIST    skip compressing files with suffix in LIST
  283. ##
  284. ####            --no-OPTION             turn off an implied OPTION (e.g. --no-D)
  285. ##            --only-write-batch=/root/hackyshome_rsync.log
Add Comment
Please, Sign In to add comment