how to backup and ftp sqlite db

90 views
Skip to first unread message

Frank von Thienen

unread,
Jun 15, 2020, 9:02:32 AM6/15/20
to weewx-user
Hi all,

I have not much knowlwdge about shell scripting, so I have to ask.
I need the follwoing action in a shell script, so I can do a cron out of it.
1. stop weewx (/etc/init.d/weewx stop)
2. ftp the sqlite.db from it's directory to a given directory (outside raspberry) with a time stamp (so time stamp should be added while transferring via ftp
3. start weewx (/etc/init.d/weewx start)

can anyone give me a helping hand.

thanks

Frank

gjr80

unread,
Jun 17, 2020, 8:18:18 PM6/17/20
to weewx-user
Hi,

You are probably going to need to do a little research. This or similar questions have come up a number of times over the years. You will find there are many solutions, some good, some better, but I suspect each being suitable in the users own circumstances. A few thoughts:

1. Unless you are using an extremely short archive interval there should be no need to stop WeeWX
2. A safe approach is to make a local copy of your database and then compress/transfer/rename or otherwise process this local copy
3. There can be a tendency to want to backup immediately after midnight, that is fine but the first archive period after midnight can be a busy period for WeeWX. Schedule your backup for the next archive period or later or once you are certain WeeWX has finished archiving/reporting etc.
4. What ever solution you adopt check that it works, I know of at least one user who thought they were backing up their sqlite db only to find when the crunch came their backup was corrupt/unreadable.

You might find this thread has some helpful information.

Gary

Michael Sanphillipo

unread,
Jun 18, 2020, 8:17:28 AM6/18/20
to weewx-user
I've been using this script that I found and run it through sudo crontab it is named weewx_backup.sh. I know it's probably overkill but I run it every 2 hours via cron. You will need to modify the backup location to match your liking.

#!/bin/bash





# A script to backup weewx configuration files to NAShostname (and SQLite data until MySQL service can be restored)





# While SQLite is being used, the service needs to be stopped before copying the data file to avoid corruption if the system is writing to the file during copy.


/etc/init.d/weewx stop


sleep 5





# Perform backup


rsync -r        /etc/weewx              /home/pi/myNAS/etc


rsync -r        /usr/share/weewx/user   /home/pi/myNAS/usr


rsync -r        /var/lib/weewx          /home/pi/myNAS/var


rsync -r        /etc/weewx              /media/pi/BACKUP/etc


rsync -r        /usr/share/weewx/user   /media/pi/BACKUP/usr


rsync -r        /var/lib/weewx          /media/pi/BACKUP/var




# Brinf weewx service backup.


/etc/init.d/weewx start



- show quoted text -
Reply all
Reply to author
Forward
0 new messages