Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:linux:backup:full-rsync [2012/06/14 00:06] – alex | en:linux:backup:full-rsync [2020/04/29 06:04] (current) – [backup-system] alex | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| * '' | * '' | ||
| * '' | * '' | ||
| - | * '' | + | * '' |
| * '' | * '' | ||
| * '' | * '' | ||
| - | If you want to use this script with a remote host, change flags to | + | If you want to use this script with a remote host where the target user is not root, change flags to |
| < | < | ||
| - | flags="-avPse ssh --delete --rsync-path=\"rsync --fake-super\"" | + | flags=(-avPse ssh --delete |
| </ | </ | ||
| Line 20: | Line 20: | ||
| ====== backup-system ====== | ====== backup-system ====== | ||
| - | < | + | < |
| #!/bin/bash | #!/bin/bash | ||
| set -f | set -f | ||
| - | hostname=$(uname -n) | + | hostname=$(hostname |
| target=" | target=" | ||
| source_dir="/" | source_dir="/" | ||
| target_dir="/ | target_dir="/ | ||
| - | exclude_dir="*/.gvfs /media /run/media /sys /dev /proc /mnt /tmp pagefile.sys hiberfil.sys / | + | exclude_dir=(*/.gvfs /media /run/media /sys /dev /proc /mnt /tmp pagefile.sys hiberfil.sys / |
| - | include_dir="/ | + | include_dir=(/ |
| - | flags="-avP --delete" | + | flags=(-avPAX --delete |
| if [ -n " | if [ -n " | ||
| Line 40: | Line 40: | ||
| fi | fi | ||
| - | include="" | + | include=() |
| # process include directories | # process include directories | ||
| - | for d in $include_dir | + | for d in "${include_dir[@]}" |
| do | do | ||
| found=0 | found=0 | ||
| dir="" | dir="" | ||
| - | | + | |
| - | | + | |
| - | + | | |
| # Need to deal with rsync idiosyncracies | # Need to deal with rsync idiosyncracies | ||
| # by including excluded directories | # by including excluded directories | ||
| Line 55: | Line 56: | ||
| # Removes matches to the include directory | # Removes matches to the include directory | ||
| # and finds the shortest parent path | # and finds the shortest parent path | ||
| - | for d2 in $exclude_dir | + | for d2 in "${exclude_dir[@]}" |
| do | do | ||
| + | echo exclude_dir $d2 | ||
| + | | ||
| if [[ $d = $d2* ]]; then | if [[ $d = $d2* ]]; then | ||
| found=1 | found=1 | ||
| - | | + | |
| - | if [[ -z " | + | if [[ " |
| shortest_parent=$d2 | shortest_parent=$d2 | ||
| else | else | ||
| Line 67: | Line 70: | ||
| fi | fi | ||
| fi | fi | ||
| - | | ||
| - | else | ||
| - | exc_dir=" | ||
| fi | fi | ||
| + | echo shortest_parent $shortest_parent | ||
| done | done | ||
| - | | + | |
| if [[ $found ]]; then | if [[ $found ]]; then | ||
| - | | + | |
| - | path=`dirname " | + | |
| while [[ " | while [[ " | ||
| - | exclude_dir=" | + | exclude_dir+=(" |
| - | | + | |
| - | | + | |
| - | path=`dirname " | + | break |
| + | fi | ||
| + | path=$(dirname " | ||
| done | done | ||
| fi | fi | ||
| - | | + | |
| - | include=" | + | include+=(" |
| done | done | ||
| - | exclude="" | + | exclude=() |
| - | for d in $exclude_dir | + | for d in "${exclude_dir[@]}" |
| do | do | ||
| - | exclude=" | + | exclude+=(" |
| done | done | ||
| - | sudo -E rsync $flags $include $exclude " | + | sudo -E rsync "${flags[@]}" "${include[@]}" "${exclude[@]}" |
| </ | </ | ||