[weewx-user] Re: Create backup image of the running system
I wrote this script to do an incremental backup of my running system. Use at your own risk. This script reads the weewx.sdb tables and insert/updates records in a backup database. It gets the last datetime from each of the weewx archive* tables. For the archive table, it inserts any new records in the backup database. For the archive_day_* tables, it deletes the last record in the backup database and then inserts any new records. The exception is the archive_day__metadata table. It is not touched. I copied the weewx.sdb file to weewxCopy.sdb and then run the following to backup the database. zkwx_incrementCopy.py -f PATH_TO/weewx.sdb -t PATH_TO/weewxCopy.sdb Good Luck, Oscar On Sunday, December 25, 2016 at 2:55:39 AM UTC-7, Per Edström wrote: > > I run my Weewx on Raspberry Pi and on a "PC" (Ebox 3350 and Ubuntu 10). > Both have the OS on an SD/SDHC-card. > > Now, I find it messy to create a backup image: > 1. Halt system > 2. Power down > 3. Remove SD-card > 4. Put in laptop and create an image to file (5-10 min) > 5. Insert SD-card in taget again and power up. > 6. Write image file to new SD-card (15-20 min). > > (NB! I have noted that not all 16GB SD-card have the exact same size, it > varies quite a lot. This became an issue the trying to find a new SD-card > for the one that failed..) > > This procedure takes time and requires quite a lot of physical > intervention. > > Is there any way of to create or maintain an updated image from the > running system. Maybe it's Ok to just backup some files (user installed)? > > Also, it would be nice to have this "backup SD" as an alternative boot > SD-card in case the primary one fails. I don't know if that is possible.. > -- 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. For more options, visit https://groups.google.com/d/optout. #!/usr/bin/python # Filename: zk_wx_incrementCopy.py # Description: This script eads the weewx.sdb tables and insert/updates # records in a backup database. It gets the last datetime from the archive* # tables. For the archive table, it inserts any new records in the backup # database. For the archive_day_* tables, it deletes the last record in the # backup database and then inserts any new records. It does not copy the # archive_day__metadata table. # ### # DateAuthorComment # 2016-12-16 obarlow Create initial script # IMPORT libraries import datetime import getopt import os.path import sqlite3 import sys # define Variables debugLevel = 1 # Connect to a data base def connect_db( sqliteDB, readOnly ): connection = None try: if readOnly == True: #connection = sqlite3.connect(sqliteDB + '?mode=ro') connection = sqlite3.connect(sqliteDB) else: connection = sqlite3.connect(sqliteDB) return connection except sqlite3.Error, e: print "Error opening DB %s:" % sqliteDB print "Error %s:" % e.args[0] sys.exit(1) # Execute sql def execute_sql( connection, sqliteSQL ): try: cursor = connection.cursor() cursor.execute(sqliteSQL) return cursor except sqlite3.Error, e: print "Error SQL %s:" % sqliteSQL print "Error %s:" % e.args[0] sys.exit(1) # getStartTime def getStartTime(i_archiveCon ): SQL = 'SELECT min(dateTime) minTime from archive' wvArchiveCur = execute_sql( i_archiveCon, SQL ) wvArchiveRow = wvArchiveCur.fetchone() return wvArchiveRow[0] # get parameters try: opts, args = getopt.getopt(sys.argv[1:],"f:t:") except getopt.GetoptError: print 'no parms' sys.exit(2) if opts: for opt, arg in opts: if opt == '-f': sourceDB = arg elif opt == '-t': targetDB = arg e
[weewx-user] Re: Create backup image of the running system
This doesn't address backing up a running system so feel free to ignore it. The varying SD card size problem can be overcome by shrinking the backup image you created using the laptop. I have a script that I use for that purpose here: https://github.com/Alanb603/Pi_Image_Shrinker/blob/master/autoresize.sh I usually make a new image backup when I make a system change and I use crontab to execute a script (generously provided by a member of this group) to copy the weewx database to Amazon S3 twice a day. A restore is simply writing the image to a new SD card then replacing the database with the the backup copy of the database from my Amazon S3 cloud. I don't quite trust hot backups for the full OS yet so I do cold backups as you have described. My system changes are pretty infrequent so the process doesn't bother me. When I have an SD card failure, I can be back up in less than 30 minutes with at worst 12.5 hours of data lost. On Sunday, December 25, 2016 at 4:55:39 AM UTC-5, Per Edström wrote: > > I run my Weewx on Raspberry Pi and on a "PC" (Ebox 3350 and Ubuntu 10). > Both have the OS on an SD/SDHC-card. > > Now, I find it messy to create a backup image: > 1. Halt system > 2. Power down > 3. Remove SD-card > 4. Put in laptop and create an image to file (5-10 min) > 5. Insert SD-card in taget again and power up. > 6. Write image file to new SD-card (15-20 min). > > (NB! I have noted that not all 16GB SD-card have the exact same size, it > varies quite a lot. This became an issue the trying to find a new SD-card > for the one that failed..) > > This procedure takes time and requires quite a lot of physical > intervention. > > Is there any way of to create or maintain an updated image from the > running system. Maybe it's Ok to just backup some files (user installed)? > > Also, it would be nice to have this "backup SD" as an alternative boot > SD-card in case the primary one fails. I don't know if that is possible.. > -- 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. For more options, visit https://groups.google.com/d/optout.
[weewx-user] Re: Create backup image of the running system
I use raspiBackup to make online image of my SD card after I saw it mentioned by someone else on this board. https://www.linux-tips-and-tricks.de/en/raspberry/303-pi-creates-automatic-backups-of-itself I keep my database, config files and webpages on a NFS share which has its own backup. Because of this, once a month I run raspiBackup to make a DD image of the RPI. It does slow the RPI3 down to the point it will not generate the weewx HTML pages, but it will still log the archive interval and post info to wunderground. Scott On Sunday, December 25, 2016 at 3:55:39 AM UTC-6, Per Edström wrote: > > I run my Weewx on Raspberry Pi and on a "PC" (Ebox 3350 and Ubuntu 10). > Both have the OS on an SD/SDHC-card. > > Now, I find it messy to create a backup image: > 1. Halt system > 2. Power down > 3. Remove SD-card > 4. Put in laptop and create an image to file (5-10 min) > 5. Insert SD-card in taget again and power up. > 6. Write image file to new SD-card (15-20 min). > > (NB! I have noted that not all 16GB SD-card have the exact same size, it > varies quite a lot. This became an issue the trying to find a new SD-card > for the one that failed..) > > This procedure takes time and requires quite a lot of physical > intervention. > > Is there any way of to create or maintain an updated image from the > running system. Maybe it's Ok to just backup some files (user installed)? > > Also, it would be nice to have this "backup SD" as an alternative boot > SD-card in case the primary one fails. I don't know if that is possible.. > -- 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. For more options, visit https://groups.google.com/d/optout.