May 8 2011

del.icio.us backup script

elderpyre

Wrote a bash script that will download my del.icio.us bookmarks locally, then delete any backups older than 3 days. Going to run it as a cron job. Never got back to making it work as a cron job. Figured I’d share. :)

#!/bin/bash
 
user='your username'
password='your password'
backupdir='/var/media/backups/delicious/'
 
backupfile='delicious_'$(date --rfc-3339=date)'.xml'
log='/var/log/delicious_backup.log'
old=$(find $backupdir -mtime +3 -type f -iname 'delicious*')
 
#get bookmarks
wget --user=$user --password=$password -O $backupdir$backupfile https://api.del.icio.us/v1/posts/all &>>$log
 
#check to see if backup is a sane size
if [ $(stat -c%s $backupdir$backupfile) -lt 1024 ]; then
     zenity --error --text "Del.icio.us backup is borked!"
else
     #delete backups older than 3 days
     if [ -n "$old" ]; then
          rm $old;
     fi
fi
 
#keep log file size in check. remove entry older than 30 days.
if [ $(stat -c%s $log) -gt 43008 ]; then
     sed -i '1,25d' $log
fi
 
exit 0
Share