Last active
March 18, 2017 21:52
-
-
Save paxperscientiam/2978eba44271aa629b6f8b0dffbeb66c to your computer and use it in GitHub Desktop.
Example of syncing website from local to remote
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/opt/local/bin/bash | |
| user='user' | |
| domain='domain.tld' | |
| source='/absolute/path/to/dir/above/transfer/point' | |
| target="${user}@${domain}:/home/" | |
| # | |
| # non-perishable | |
| BLACKLIST=( | |
| ".DS_Store" | |
| "*#*" | |
| ".cache" | |
| ".ssh" | |
| "logs" | |
| "opcache.php" | |
| "testing" | |
| ); | |
| # this stuff is NOT touched at all on the remote side | |
| # asolutes are with respect to the transfer point! | |
| PROTECTLIST=( | |
| "P .cache/" | |
| "P /${user}/.ssh" | |
| "P /${user}/logs" | |
| "P /${user}/.bash_history" | |
| "P /${user}/.emacs.d" | |
| "P php.log" | |
| ); | |
| # | |
| # --dry-run | |
| function sync () { | |
| composer dumpautoload -o | |
| rsync -e '/usr/bin/ssh -T -x' \ | |
| --numeric-ids \ | |
| --prune-empty-dirs \ | |
| --delete \ | |
| --filter='-p .DS_Store' \ | |
| --exclude-from <(printf '%s\n' "${BLACKLIST[@]}") \ | |
| --filter='. '<(printf '%s\n' "${PROTECTLIST[@]}") \ | |
| --delete-excluded \ | |
| --archive \ | |
| --progress \ | |
| --times \ | |
| --copy-links \ | |
| --verbose \ | |
| "${source}" "${target}" | |
| } | |
| sync "$@" | |
| # | |
| # | |
| # reset PHP (cgi) | |
| /usr/bin/ssh -vTx "${user}"@"${domain}" 'killall -9 php56.cgi' | |
| #### NOTES | |
| # -p (with filter) perishable means ignore if deleting directing anyway | |
| # --prune-empty-dirs remove empty remote dirs | |
| # --delete-excluded delete remote not on sender and delete files in exclude array | |
| # --exclude items are relative to transfer point | |
| # ssh | |
| # T: turn off pseudo-tty to decrease cpu load on destination. | |
| # c arcfour: use the weakest but fastest SSH encryption. Must specify "Ciphers arcfour" in sshd_config on destination. | |
| # o Compression=no: Turn off SSH compression. | |
| # x: turn off X forwarding if it is on by default. | |
| # This creates an archive that does the following: | |
| # rsync (Everyone seems to like -z, but it is much slower for me) | |
| # a: archive mode - rescursive, preserves owner, preserves permissions, preserves modification times, preserves group, copies symlinks as symlinks, preserves device files. | |
| # H: preserves hard-links | |
| # A: preserves ACLs | |
| # X: preserves extended attributes | |
| # x: don't cross file-system boundaries | |
| # v: increase verbosity | |
| # --numeric-ds: don't map uid/gid values by user/group name | |
| # --delete: delete extraneous files from dest dirs (differential clean-up during sync) | |
| # --progress: show progress during transfer |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
USE AT YOUR OWN PERIL