Saturday, September 22, 2018
Automated XLog backup
Though no longer required, lots of old-school Radio Amateurs keep a log. Some use pencil and paper, but most do it digitally (and some, like me, do both). Belt and suspenders.
With that in mind, I have written a Linux script that will help me avoid manual re-creation of my digital Amateur Radio log from the pencil and paper copy - which dates back to 1970 - when the computer finally fails. I use XLog, but this should work for other Linux logging programs.
You will need some basic familiarity with Linux scripting and permissions, have crontab up and running and Dropbox installed.
The general scheme is to copy the XLog log file to a safe place at least once a day. When my computer dies (and they all will), I could re-install XLog on a replacement and retrieve the latest of my daily log file copies kept remotely by Dropbox.
The scheme has three parts:
(1) Linux 'crontab'
(3) The 'xlog_backup.cmd' script
Linux has a very handy program that allows users to schedule events at intervals. I will not do a tutorial on cron or crontab, but will just show you the appropriate crontab file entry, below:
# min hour day month day of command
30 * * * * /home/MYHOME/bin/xlog_backup.cmd
Crontab reads this file and is directed to run the command xlog_backup.cmd (in the directory given) on the half-hour of every hour of every day of every month on every day of the week. For you old timers, that's every time Mickey's long arm points down.
Dropbox is a commercial file sharing and storage program. There is a fee if you want to store lots of data, but since XLog files are relatively tiny, we can just use the free ('Basic') version. Check out:
You will have to create an account. The script below could possibly work with another file-sharing program that works in a similar fashion. Your decision. I have no commercial interest in Dropbox, but it is quite handy for things other than saving Amateur Radio log files.
One you have Dropbox running and understand how it works, make a subdirectory, perhaps named "XLog", to match the script location below.
Here is the backup script. You will have to edit the various lines that are unique to your application - one example is the name of XLog's log file. XLog typically keeps this file in the hidden directory '.xlog'. Mine is named wb5bkl.xlog.
Make a copy of the script below and edit it:
# Rev 002 07-05-2018 remove all but last 10 files
# Rev 001 12-13-2017 turn off report that file exists
# Rev 000 12-12-2017 initial coding
# check to see if a dropbox backup exists for today
##< edit the path to the Dropbox Xlog directory and your log name >##
if [ -e /home/MYHOME/Dropbox/XLog/LOGNAME.xlog.`date +%j` ]
#echo -e "\n wb5bkl.xlog.`date +%j` exists - quitting xlog_backup.cmd."
# Get rid of all but the 10 most recent log backups
##< again edit the path and file name and how many to keep >##
rm -f $(ls -1t /home/MYHOME/Dropbox/XLog/MYLOG.xlog* | tail -n +11)
# Copy current MYLOG.xlog file to Dropbox
##< edit both paths and file names >##
cp /home/MYHOME/.xlog/MYLOG.xlog /home/MYHOME/Dropbox/XLog/MYLOG.xlog.`date +%j`
Save the edited copy in your 'bin' directory (or wherever - but match your crontab entry) and make it executable. The script only makes one copy per day - safe enough for me - but you can modify the if/then routine above and the crontab entry to suit your needs.
The backup file will have the name MYLOG.xlog.Julian_date, for example: wb5bkl.xlog.147
I hope this works for you - and keeps your log(s) nice and safe.
cln - Nick