bin/backer-upper-0.7.5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
#!/usr/bin/env bash # Synchronizes the destination to the source, preserving metadata (owner, # group, permissions, timestamps, etc...) and symbolic links. It also skips # replacing files based on a calculated checksum, which can save a lot of time # with backups! ssh is used for encryption, and the script displays the sync # progress with what SHOULD be human-readable numbers. # - x1phosura # '-a' preserves attributes like permissions, owner/group, and more # '-v' is verbose # '-h' is "human readable" # '-c' compares files to-be synced/ transfered, if already existing, by # checksum (rather than by filesize or modified time) # '--stats' and '--progress' simply show a lot of info about the file transfers # '-z' compresses data during the transfer options="-avhcz --stats --progress" # TODO: rework to take command-line arguments echo "If the destination is remote, enter '(y)es'; otherwise, press enter: " read remote if [ "$remote" != "" ]; then echo "Enter the username for the remote machine: " read ruser echo "Enter the hostname (if DNS) or IPv4 address for the remote machine: " read rhost # '-e' specifies the remote shell to use (ssh here) options="$options -e ssh" dest="${ruser}@${rhost}:~/" else echo "Enter the path to the destination directory: " read dest fi echo "Delete files at destination not present in source directories? (y/n):" read del_remote if [ "$del_remote" = "y" ]; then # TEST THIS OPTION OUT BEFORE USE!! # '--delete' deletes files at the destination that are NOT present from the # source. USE CAREFULLY!! '--force' modifies '--delete' to handle something # do to with non-empty directories being deleted or overridden, so I'm # guessing I want it echo "Extraneous files found in destination will be deleted." options="$options --delete --force" elif [ "$del_remote" = "n" ]; then echo "Extraneous files found in destination will be kept." else echo "Error: expected 'y' or 'n' character as input. Aborting for safety..." exit 1 fi # Note: as they currently stand, DO NOT add trailing slashes to these # filenames!! Why? Here is the best explanation I've seen as to how trailing # slashes work in rsync: # Without a slash on the source directory means copy both the source # directory, and the contents (recursively if specified) to the destination # directory while adding a trailing slash means only copy the contents of # the source directory, recursively if specified, to the destination. # TODO: auto-generate paths (or read from textfile) instead of hardcoding filelist="$HOME/73h4x \ $HOME/Desktop \ $HOME/Documents \ $HOME/Downloads \ $HOME/Library \ $HOME/Subgenius \ $HOME/tmp" # copy from here to destination (remote or local) # Note: destination needs to be left unquoted for this to work rsync $options $filelist "$dest" |