Demo Discussion
Forum Config Examples Contributions Vulnerabilities
  Contributions to ELOG  Not logged in ELOG logo
Message ID: 38     Entry time: Fri Sep 9 12:08:26 2011
Author: Andreas Luedeke 
Author Email: andreas.luedeke@psi.ch 
Category: Script 
Subject: create incremental daily backups of logbooks for Unix/Linux 
Status: Beta 
Last Revision:  
A very simple backup utility for elog logbooks.
If you want to recover your logbook from corrupted entries, an incremental backup comes in handy:
you can just replace the corrupted files with the previous versions.
Below is a very simple wrapper to create backups of the logbook into some local directory (/logbooks_backup in
the example script). The second wrapper lists the files in a given ".tar" archive.

You would run the backup from a cron job with the line:
1 0 * * * /usr/local/elog/elog_backup_daily

This will create daily backups of modified logbook and config files and a weekly backup of the password file
/usr/local/elog/passwd.txt (if you wonder why: our passwd.txt file has more than 1 MByte and of course it
changes with every login).

elog_backup_daily (copy to /usr/local/elog) script to create tar file and remove tar files older than 90 days
exclude-logbooks  (copy to /usr/local/elog) list of files to be excluded in backup (thumbnails, etc.) 
elog_backup_listfiles (copy to /usr/local/bin) shows content of a given tar file (omits directories in list)
Attachment 1: elog_backup_daily  744 Bytes  | Hide | Hide all
#!/bin/sh
# source file directory
srcd=/usr/local/elog/

# backup all files newer than 25 hours
date=$(date -d "-25hours" "+%Y%m%d %H:%M")
# backup file directory
tard=/logbooks_backup
# backup tar file name
tarf=$tard/$(date +%Y%m%d_%a.tar)
# do not backup files that match patterns in this file
excf=/usr/local/elog/exclude-logbooks
# create backup
cd $srcd
tar --ignore-case -X $excf --newer "$date" -cf $tarf . logbooks/*

# copy passwd.txt
if [ "$(date +%u)" -eq 1 ]
then
	passwd=$tard/passwd_$(date +%Y%m%d_%a.txt)
	cp $srcd/passwd.txt $passwd
	gzip -9 $passwd
fi
# delete all backups older than 90 days
find $tard -mtime +90 -name "*_???.tar"           -exec rm -f {} +
find $tard -mtime +90 -name "passwd_*_???.txt.gz" -exec rm -f {} +
Attachment 2: exclude-logbooks  123 Bytes  | Hide | Hide all
*.png.png
*.gif.png
*.jpg.png
*.pdf.png
oldLogbooks/*
logbooks/elog.log
passwd.txt
ssl/*
logbooks/Backup/*
logbooks/old/*

Attachment 3: elog_backup_listfiles  27 Bytes  | Hide | Hide all
tar -tf $1|grep -v "^.*/$"
ELOG V3.1.5-fe60aaf