Last active
August 29, 2015 14:22
-
-
Save yarwelp/248a90bd42de0798d847 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
#!/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 |
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.
Does not detect changes in ownership/permissions. Fixed. (See note in comment below.)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.
(Contents of this comment moved inline of script.)
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
I should probably justDone.-exec
fromfind
in that one place where I'm piping toxargs
.