Created
February 13, 2013 03:54
-
-
Save adam12/4942128 to your computer and use it in GitHub Desktop.
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
| #!/bin/bash | |
| set -x | |
| log() { echo $*; } | |
| HOSTS="host1 host2" | |
| TODAY=$(date +%Y%m%d) | |
| YESTERDAY=$(date +%Y%m%d -d '1 day ago') | |
| for host in $HOSTS; do | |
| [[ ! -d "$host" ]] && mkdir "$host" | |
| cd "$host" | |
| if [[ ! -d "$TODAY" && -d "$YESTERDAY" ]]; then | |
| log "Using backups from $YESTERDAY" | |
| cp -r "$YESTERDAY" "$TODAY" | |
| elif [[ ! -d "$TODAY" ]]; then | |
| mkdir "$TODAY" | |
| fi | |
| log "Performing rsync of admin@$host:admin_backups/" | |
| rsync -avz --delete -e ssh "admin@$host:admin_backups/" "$TODAY/" | |
| log "Cleaning up folders older than 7 days" | |
| find . -maxdepth 1 -type d -mtime +7 -print -exec rm -rf "{}" \; | |
| cd - | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment