Skip to content

Instantly share code, notes, and snippets.

@yarwelp
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yarwelp/248a90bd42de0798d847 to your computer and use it in GitHub Desktop.
Save yarwelp/248a90bd42de0798d847 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Made by erikano for use on FreeBSD 10.1
#
# This script assumes that a previous backup exists
# with the expected file name format.
#
# You need to change some stuff if you want to use this.
#
# * Script is using hard-coded directory names and such.
#
# * No effort has been made to make this script portable.
# E.g. GNU stat does not understand what we're saying here.
# Though this script will detect files with changes to ownership/permissions
# thanks to checking ctime, one might argue that it's inefficient to backup
# the whole file again for inode changes only. That is true, but so is
# the fact that backing up a whole file again for as little as
# a single byte change is almost as inefficient. This is a design decission and
# I'm sticking with it until the effect of this choice forces me
# to do something about it.
export TZ=Europe/Oslo
cd /usr/local/www/
cmp=$( find ~/backup/ -name www-erikano-net-archive\* \
-exec stat -f "%Sm %N" -t "%Y-%m-%d %H:%M" {} \; \
| sort -n -r \
| head -n1 )
find net.erikano.www/ ! -path net.erikano.www/ \
-newer "$( echo $cmp | cut -d' ' -f3- )" \
-or -cnewer "$( echo $cmp | cut -d' ' -f3- )" \
| cmp -s /dev/null -
if [ $? -ne 0 ] ; then
tar \
--exclude-from ./net.erikano.www/.backup-exclude \
--newer "$( echo $cmp | cut -d' ' -f1-2 )" \
-cvf ~/backup/www-erikano-net-archive-incr-$( date +%Y-%m-%dT%H%M%S%z).tar \
net.erikano.www/
fi
@yarwelp
Copy link
Author

yarwelp commented Jun 12, 2015

I should probably just -exec from find in that one place where I'm piping to xargs. Done.

@yarwelp
Copy link
Author

yarwelp commented Jun 13, 2015

Changed as per comment above. Also decided to sort in reverse order and take the first line instead of normal sort and last line. Also, sorting numerically now.

@yarwelp
Copy link
Author

yarwelp commented Jun 13, 2015

Does not detect changes in ownership/permissions. tar will notice, though, so if there are other changes, tar will also include the files on which ownership/permissions changed. Must look into the different time stamps and what I'm checking on. Fixed. (See note in comment below.)

@yarwelp
Copy link
Author

yarwelp commented Jun 13, 2015

(Contents of this comment moved inline of script.)

@yarwelp
Copy link
Author

yarwelp commented Jun 14, 2015

Created a repository for what'll replace this. https://github.com/erikano/binc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment