3 ms·
keep multiple snapshots so that you can recover files after you delete them yourself. #!/bin/sh AWS_ACCESS_KEY_ID=<> AWS_SECRET_ACCESS_KEY=<> BUCKET=<> DIR
by aolnerd 17y ago
keep multiple snapshots so that you can recover files after you delete them yourself.
#!/bin/sh
AWS_ACCESS_KEY_ID=<>
AWS_SECRET_ACCESS_KEY=<>
BUCKET=<>
DIR=<>
S3SYNC=/usr/bin/s3sync.rb
DAYS_TO_KEEP_BACKUPS=30
# colons in path confuse s3sync
DATE=$(date +%F_%H-%M-%S)
NEWEST=$(/bin/ls -r $DIR | grep -v current | head -1)
# copy the newest copy of files into a new directory, creating hardlinks instead of duplicate files
cp -al $DIR/$NEWEST/ $DIR/$DATE/
# sync the s3 bucket against the new directory
$S3SYNC --recursive --make-dirs --delete --no-md5 -v $BUCKET: $DIR/$DATE/ 2>&1 | grep -v 'Could not change owner'
# update the "current" symlink link
test -e $DIR/current && rm $DIR/current
ln -sf $DIR/$DATE $DIR/current
# remove snapshots older than DAYS_TO_KEEP_BACKUPS days
find $DIR -maxdepth 1 -type d -mtime +$DAYS_TO_KEEP_BACKUPS -print0 | xargs -0 --no-run-if-empty rm -rv