Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [[ $# -ne 3 || ( "$1" != "backup" && "$1" != "restore") ]]; then
- echo "Usage: $0 [backup|restore] source destination"
- exit 1
- fi
- date=`date "+%Y-%m-%d-%H-%M-%S"`
- SRC="$2"
- DST="$3"
- if [ ! -d "$SRC" ]; then
- echo "$SRC" is not a directory or does not exist
- exit 1
- fi
- if [ ! -d "$DST" ]; then
- echo "$DST" is not a directory or does not exist
- exit 1
- fi
- function rsync_backup() {
- # $1 = SRC, $2 = DST, $3 = date
- SRC="$1"
- DST="$2"
- date="$3"
- rsync --recursive --links --perms --times --group --owner --devices --specials --verbose --delete --numeric-ids \
- --exclude={/dev/*,/proc/*,/mnt/*,/media/*,/sys/*,/tmp/*,/run/*,/home/*/.gvfs,/home/*/.cache,/var/lib/pacman/sync/*,/var/cache/pacman/pkg/*,/home/*/tmp/*,/home/*/VirtualBox\ VMs,/home/*/.dbus,/swapfile,/home/*/.thumbnails,/home/*/.wine,/home/*/.davfs2/cache,/home/*/.gksu.lock,/home/*/.gmrun_history,/home/*/Downloads/*,/home/*/.local/share/Trash} \
- --link-dest="`readlink -f "$DST"`/Latest" \
- $SRC $DST/Processing-$date \
- && cd $DST \
- && mv Processing-$date $date \
- && rm -f Latest \
- && ln -s $date Latest
- }
- function rsync_restore() {
- # $1 = SRC, $2 = DST, $3 = date
- SRC="$1"
- DST="$2"
- date="$3"
- rsync --recursive --links --perms --times --group --owner --devices --specials --verbose --delete --numeric-ids \
- $SRC $DST
- }
- if [[ $1 == "backup" ]]; then
- rsync_backup $SRC $DST $date
- fi
- if [[ $1 == "restore" ]]; then
- rsync_restore $SRC $DST $date
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement