This comes up very frequently as new weewx users come onboard.   Take a 
look back at the weewx-users archives for lots of previous (excellent) 
discussions for how to automate backing up your db and 'verifying' that the 
backup is restorable.

There's an old sysadmin credo saying that if you haven't tried a restore, 
you didn't really do a backup.  Believe it.  Been there.

There was a long discussion years ago (HERE) 
<https://groups.google.com/g/weewx-user/c/ha-mbc6zkpY> where lots of folks 
went through the pros+cons and how they approach the problem.  The short 
answer is to use the 'pragma integrity_check' command in sqlite3 to 
validate your backups are good.   Other finding was that you probably don't 
need to shut weewx down to do a backup.

The canonical way at that time seemed to be:

   - copy your database to /var/tmp or something to make a copy of the 
   running db
   - use sqlite3 commands to dump 'that' to a text file
   - gzip the dump file up and save it someplace on another system
   - delete your scratch copy of the db

Lots of people have posted a variety of ways to do this with Dropbox, 
Amazon S3, and simple scp commands, so dig around in the archives a bit for 
some options.

FWIW, back then I found experimentally that a simple '*copy the database, 
then gzip the copy and save it'* was good enough.  I went back 100 backups 
and verified that all the backups were good, so I personally don't bother 
doing a .dump of the db to save a copy.  I just make a copy of the current 
db and compress+save the copy. The script I cooked up years ago that has 
always worked for me is (HERE) 
<https://github.com/vinceskahan/vds-weewx-backup-data> on Github.

On Sunday, January 10, 2021 at 2:32:47 PM UTC-8 stelli...@gmail.com wrote:

> Good point. Doing all this without stopping weewx is much nicer. In fact, 
> after a year of data (in my case), the sqlite3 approach will not take that 
> long. I will try that as well.
>
> I see that data backup seems to be a hot topic...
>
> tke...@gmail.com schrieb am Sonntag, 10. Januar 2021 um 14:39:13 UTC+1:
>
>> Your approach will certainly work, but requires stopping weewxd for what 
>> could potentially be a long period of time, so you might miss a weather 
>> event.
>>
>> Another approach is to use the sqlite3 ".backup" command. Replace your 
>> tar command with
>>
>> tar czf $dest/$archive_file $backup_files2 $backup_files3 $backup_files4
>> sqlite3 $backup_files1 ".backup $dest/$backup_files1.backup"
>>
>> This avoids stopping weewxd, because the sqlite3 utility will take care 
>> of any necessary locking. However, it has the disadvantage that if sqlite3 
>> holds on to the lock for too long, a database write will get delayed and, 
>> ultimately, could time out, causing weewxd to restart.
>>
>> Finally, the most sophisticated approach is to incrementally back up the 
>> database. Take a look at this page on backing up a running database 
>> <https://sqlite.org/backup.html>. It copies a number of database pages, 
>> then releases the lock, sleeps for a bit to allow other processes to gain 
>> access to the database, then goes on to the next set of pages. This allows 
>> the database to be backed up without stopping weewxd, and without the 
>> potential hazard of a database timeout.
>>
>> Something to think about...
>>
>> -tk
>>
>>
>>
>> On Sun, Jan 10, 2021 at 4:01 AM Jan Stelling <stelli...@gmail.com> wrote:
>>
>>> For some time, I was looking for an easy and independent (from weewx) 
>>> way to automatically backup my weewx data, as I do not want to lose data if 
>>> the Micro SD breaks down.
>>> Recently, I found this small repo 
>>> <https://github.com/PapyLeCelte/Weewx-Backup> on github which only 
>>> contains a backup script file. It mounts a USB drive, stops weewx, creates 
>>> an archived backup of the most relevant user files and folders on the USB 
>>> drive, unmounts the drive and restarts weewx.
>>>
>>> This was almost perfect for me, but I had to introduce some changes to 
>>> make it suitable for my environment. I forked it 
>>> <https://github.com/jnstllng/Weewx-Backup> to make it available for 
>>> others. It now does the following:
>>>
>>>    1. Stop weewx
>>>    2. Create an archived backup on a mounted network drive (under 
>>>    /home/pi/Shares/Temp)
>>>    3. Start weewx
>>>
>>> I tested it manually and running via crontab on my RasPi 3B.
>>>
>>> Maybe this is useful for some of you...
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "weewx-user" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to weewx-user+...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/weewx-user/2671c065-719a-4435-9657-06841af8fed7n%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/weewx-user/2671c065-719a-4435-9657-06841af8fed7n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to weewx-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/be373139-1cae-4d34-9f85-0cbfa9bf8b67n%40googlegroups.com.

Reply via email to