Showing posts with label log. Show all posts
Showing posts with label log. Show all posts

Saturday, September 22, 2018

Automated XLog backup - Revised version

Back in the days when I worked for a living, one of the computer guys at the plant corrected me while I was talking about disc drives in our computers - I was saying "if it fails..."  He corrected me with "Not if it fails.  When..."

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'
     (2)  Dropbox
     (3)  The 'xlog_backup.cmd' script


'crontab'

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
#                                       week            
#    
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

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:

          https://www.dropbox.com

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.


'xlog_backup.cmd'

Here is the backup script.  This is a revised version (23 February 2019) that is slightly more logical and creates a new backup if you change your log.  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:

#!/bin/bash
#  /home/urhomedir/bin/xlog_backup.cmd
#
#
###  Edit each of the following for your situation:
###    urhomedir - your home directory
###    YOURCALL  - your callsign in CAPS
###    yourcall  - your callsign in lowercase
###  Note the asumptions about directory locations
###  including the Dropbox directory structure.
###  All the 'echo' statements can be commented out once
###  you've got it working to your satisfaction.
#
#
#  Define paths to xlog data file and Dropbox backup
YOURCALL_XLOG=/home/urhomedir/.xlog/yourcall.xlog
DROPBOX_XLOG=/home/urhomedir/Dropbox/Xlog/yourcall.xlog.`date +%j`
#

#  Housekeeping  -  comment this out if you want to keep them all
#  Get rid of all but the 10 most recent log backups
rm -f  $(ls -1t /home/urhomedir/Dropbox/Xlog/yourcall.xlog* | tail -n +11)

#
#
#
  First, check to see if the backup for today exists
#  If not, create it and exit
#
#
if [ ! -f $DROPBOX_XLOG ]
then
    # create it
    cp $YOURCALL_XLOG $DROPBOX_XLOG
    echo -e "\n Creating today's backup file:   yourcall.xlog.`date +%j` \n"
    #  place a note in .xlog containing the latest backup time
    date > ~/.xlog/Last_Cloud_Backup
    exit
    else
    :
fi
#
#  Or see if the logfile in Dropbox is newer than your logfile
#  If so, do nothing and quit
#
if [ $DROPBOX_XLOG -nt $YOURCALL_XLOG ]
    then
    echo -e "\n yourcall.xlog.`date +%j` exists and is newer."
    echo -e " Quitting xlog_backup.cmd...\n"
    exit
    else
    #  if the Dropbox version is older than the logfile, overwite it
    #  with the newer version
    cp $YOURCALL_XLOG $DROPBOX_XLOG
    echo -e "\n Overwriting today's backup file:   yourcall.xlog.`date +%j` \n"
    #  place a note in .xlog containing the latest backup time
    date > ~/.xlog/Last_Cloud_Backup
fi
#
exit
#


Save the edited copy in your 'bin' directory (or wherever - but match your crontab entry) and make it executable.  The script only makes one Dropbox copy per day - but overwrites that copy if your log changes within the last hour.  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 yourcall.xlog.Julian_date, for example:  wb5bkl.xlog.147

And the the latest backup time will be noted in your .xlog directory.  Backups from at least the last 10 days will be saved.

I hope this works for you - and keeps your log(s) nice and safe.

cln - Nick
WB5BKL
Lake Buchanan

Sunday, August 6, 2017

Importing N1MM ADIF export files into XLog


I like the N1MM Contest Logger program for Amateur Radio contesting.

N1MM is quite amazing for free software and is very well maintained. It is aimed just at contesting and covers most of the major contests worldwide. It is easy to install and – though there is a steep learning curve – once set up, solid.

It supports exports to Cabrillo (.log) for contest log submissions and to the ADIF (.adi) format for import into other logging programs.

I prefer to use Linux on my computers. My 'Amateur Radio computer' is a dual-boot machine just so that I have access to the N1MM Contest Logger and an antenna modeling program – both available only on Windows. To the best of my knowledge there is no Linux equal for N1MM.

My everyday logging program is XLog – a Linux program. After each contest, I move the results into XLog. Unfortunately a direct import of the N1MM .adi file into XLog leaves a lot to be desired for me.

N1MM exports only the start time – to 6 places (hhmmss). I like both the QSO start and end times to be entered and 4 places (hhmm) is more common. I note that QSO start and end times in a contest are almost always identical.

N1MM exports the frequency to the nearest 0.1KHz. XLog's default is to the nearest Khz.

N1MM exports both a sent and a received signal report. In the weekly CWT contests I enjoy, neither report is exchanged but N1MM defaults to reports of 599 for both. I prefer that those false reports not be entered into XLog.

N1MM does export the contest exchange, but I like to include the name of the contest following the exchange in XLog.  XLog has a different name for this field.

Here is an example of one record from the N1MM exported .adi file. Note that this is all one line:

<CALL:4>K5OT <QSO_DATE:8>20170802 <TIME_ON:6>190518 <BAND:3>15M <STATION_CALLSIGN:6>WB5BKL <FREQ:8>21.03258 <CONTEST_ID:6>CW-Ops <FREQ_RX:8>21.03258 <MODE:2>CW <NAME:5>LARRY <RST_RCVD:3>599 <RST_SENT:3>599 <TX_PWR:1>5 <OPERATOR:6>WB5BKL <CQZ:1>4 <STX:1>2 <APP_N1MM_EXCHANGE1:3>127 <APP_N1MM_POINTS:1>1 <APP_N1MM_RADIO_NR:1>1 <APP_N1MM_CONTINENT:2>NA <APP_N1MM_RUN1RUN2:1>1 <APP_N1MM_RADIOINTERFACED:1>1 <APP_N1MM_ISORIGINAL:4>True <APP_N1MM_NETBIOSNAME:11>OPTIPLEX755 <APP_N1MM_ISRUNQSO:1>0 <EOR>

And here is what I would like the same line to look like for import into XLog:

<CALL:4>K5OT <QSO_DATE:8>20170802 <TIME_ON:4>190518 <TIME_OFF:4>190518 <BAND:3>15M <STATION_CALLSIGN:6>WB5BKL <FREQ:6>21.03258 <CONTEST_ID:6>CW-Ops <FREQ_RX:8>21.03258 <MODE:2>CW <NAME:5>LARRY <TX_PWR:1>5 <OPERATOR:6>WB5BKL <CQZ:1>4 <STX:1>2 <COMMENT:15>127 CWT-1900 <APP_N1MM_POINTS:1>1 <APP_N1MM_RADIO_NR:1>1 <APP_N1MM_CONTINENT:2>NA <APP_N1MM_RUN1RUN2:1>1 <APP_N1MM_RADIOINTERFACED:1>1 <APP_N1MM_ISORIGINAL:4>True <APP_N1MM_NETBIOSNAME:11>OPTIPLEX755 <APP_N1MM_ISRUNQSO:1>0 <EOR>

I have highlighted the areas that have been modified.

I did this with a little Bash script and the sed (Streaming EDitor) command. Below is the operational part of the sed command for one of the little contests I enjoy, the CWT at 1900Z each Wednesday:

# CWT1900.sed
#
#
s/\(<TIME_ON:6>\)\([0-9]*\)/<TIME_ON:4>\2 <TIME_OFF:4>\2/
#
s/<FREQ:8>/<FREQ:6>/
#
s/<FREQ:7>/<FREQ:5>/
#
s/ <RST_RCVD:3>599 <RST_SENT:3>599 / /
#
s/\(<APP_N1MM_EXCHANGE1\)\(:[0-9]*\)>\([A-Z0-9]*\)/<COMMENT:15>\3 CWT-1900/
#
#

This sed file makes the four changes I listed above. Now I can run the .adi output files from N1MM through my little bash script and import them into XLog with no editing needed!

If you would like copies of my bash script for the three CWT contests, with the accompanying sed files and some informal notes, email me at my QRZ.com address.


cln - Nick
WB5BKL