Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- typeset -g BACKUP_STORAGE='/FullPathToYourStorage'
- typeset -g PREFIX='backup_'
- typeset -g TIME_STAMP=$(date -I)
- typeset -g BACKUP_DIR=${BACKUP_STORAGE}/${PREFIX}${TIME_STAMP}
- typeset -g PREV
- mkdir --parent --verbose ${BACKUP_STORAGE}
- if [[ -d ${BACKUP_DIR} ]]
- then
- echo 'already updated'
- exit 1
- fi
- # find least backup
- typeset -i time_diff=$(date +'%s') # seconds since 1970-01-01 UTC
- typeset -i current_time=$((time_diff))
- for dir in ${BACKUP_STORAGE}/${PREFIX}*
- do
- prev_time_stamp=$(echo $dir | sed "s;${BACKUP_STORAGE}/${PREFIX};;")
- typeset -i prev_since_utc=$(($(date --date=${prev_time_stamp} +'%s')))
- if (( current_time - prev_since_utc < time_diff ))
- then
- time_diff=$((current_time - prev_since_utc))
- PREV=$dir
- fi
- done
- # new backup or differential backup
- if [[ -z ${PREV} ]]
- then
- echo 'new backup'
- rsync --archive --verbose $1 ${BACKUP_DIR}
- else
- echo 'differential backup'
- rsync --archive --verbose --link-dest=${PREV} $1 ${BACKUP_DIR}
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement