I am in the process of industrialising my backups, but this script works 
from the command line and may give you an idea of how to backup your 
database without having to stop and start weewx. I will shortly have a post 
up on how to do this once I have it working properly

On Wednesday, January 20, 2021 at 3:39:11 AM UTC peterq...@gmail.com wrote:

> I don't know anything, but I can google...
>
> https://stackoverflow.com/questions/311691/importing-a-sqlite3-dump-back-into-the-database
>
>
> On Tue, Jan 19, 2021 at 7:35 PM Kevin Chapman <kdch...@gmail.com> wrote:
>
>> Ok the file command is showing the backups to be large ASCII files.  The 
>> backup command script is using the sqlite3 .dump command.  The ascii files 
>> are the SQL commands to rebuild the file.  Here is the code.
>>
>>
>> echo 'stop the weewx daemon and wait 30 seconds'
>> sudo /usr/sbin/service weewx stop
>> retn_code=$?
>> if [ $retn_code -ne 0 ]; then
>>   exit 7
>> fi
>>
>> sleep 30s
>>
>> echo 'dump sqlite3 database'
>> echo '.dump' | sqlite3 $WEEWX_DB | gzip -c > $DUMP_FILE
>>
>> echo 'restart the weewx daemon'
>> sudo /usr/sbin/service weewx start
>>
>> I am not good with sqlite.  I have read a few different sites talking 
>> about how to read a dump file into a database.  So far I am not having luck 
>> recovering my database.  If anyone has a site they trust or have a quick 
>> command for recovering sqlite dump files it would be much appreciated.  So 
>> far when I run sqlite3 <DB>  and then .read <dump file>  It seems to run 
>> but in about 30 seconds ends at the prompt with no errors on screen and the 
>> database file is empty.  
>>
>> Thank you all for your input and time.  
>>
>> On Monday, January 18, 2021 at 9:20:59 PM UTC-6 vince wrote:
>>
>>> On Monday, January 18, 2021 at 6:47:09 PM UTC-8 kdch...@gmail.com wrote:
>>>
>>>> Now when I try to copy the unpacked sdb and pick up where I left off I 
>>>> get a message that the file is not a database.  I have tried a couple of 
>>>> archives from Dec and Jan.  All seem to be no good.  I did notice that 
>>>> when 
>>>> I reinstalled weewx it is now version 4.3.0.  Could I be dealing with a 
>>>> system version mismatch in the file or is there something wrong with my 
>>>> backup process.  
>>>>
>>>
>>> Very likely a backup process issue, although the steps you mentioned 
>>> looked good to me.
>>>
>>> We'd need to see some actual logs or terminal errors to know for certain 
>>> what you're actually seeing.
>>>
>>> I guess what I'd do is:
>>>
>>>    - grab a recent backup, copy it to a scratch directory
>>>    - uncompress it to a .sdb file
>>>    - run 'file' against the .sdb file
>>>    - If it shows up as a sqlite3 db, then you can validate it with the 
>>>    sqlite3 utility.
>>>
>>>
>>> Good output looks like....
>>>
>>> # file weewx.sdb
>>> weewx.sdb: SQLite 3.x database, last written using SQLite version 3026000
>>>
>>> # echo "pragma integrity_check" | sqlite3 weewx.sdb
>>> ok
>>>
>>>
>>> -- 
>> 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/52eb0a6c-a7d1-4fcf-9f22-717f6bfe22fdn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/weewx-user/52eb0a6c-a7d1-4fcf-9f22-717f6bfe22fdn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> Peter Quinn
> (415)794-2264 <(415)%20794-2264>
>

-- 
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/eec4ea11-5bc5-4296-a1f3-d6b10ea5a38en%40googlegroups.com.
#!/bin/env python3
#-----------------------------------------------------------------------------------------------------------------------------------
# Routine Name: weeUpdate.py
# Author:       Mike Revitt
# Date:         19/03/2020
#------------------------------------------------------------------------------------------------------------------------------------
# Revision History    Push Down List
# -----------------------------------------------------------------------------------------------------------------------------------
# Date        | Name        | Description
# ------------+-------------+--------------------------------------------------------------------------------------------------------
#             |             |
# 17/01/2021  | M Revitt    | Initial version
#-------------+-------------+--------------------------------------------------------------------------------------------------------
# Description:  Takes a backup of a running SQLite3 database
#
# Issues:       None
#
# ***********************************************************************************************************************************
# Copyright 2020 Mike Revitt <m...@cougar.eu.com>. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# ***********************************************************************************************************************************
import sqlite3

#SQLITE_DB         = '/home/weewx/archive/weewx.sdb'
#BACKUP_DB         = '/home/weewx/weewx.sdb'
SQLITE_DB         = '/Users/revittmk/OneDrive/Mike/WebSites/Weewx/DataLoads/Ecowitt/weewx.sdb'
BACKUP_DB         = '/Users/revittmk/OneDrive/Mike/WebSites/Weewx/DataLoads/Ecowitt/weewx_backup.sdb'

def progress(status, remaining, total):
    print(f'Copied {total-remaining} of {total} pages...')

try:
    #existing DB
    sqliteCon = sqlite3.connect(SQLITE_DB)
    #copy into this DB
    backupCon = sqlite3.connect(BACKUP_DB)
    with backupCon:
        sqliteCon.backup(backupCon, pages=10000, progress=progress)
    print("backup successful")
except sqlite3.Error as error:
    print("Error while taking backup: ", error)
finally:
    backupCon.close()
    sqliteCon.close()

Reply via email to