Backup database before running a full rescan operation.

This commit is contained in:
Lucas Verney 2016-09-29 02:58:08 +02:00
parent 7cd15d4ea4
commit 71901718ce

View File

@ -10,6 +10,7 @@ import argparse
import dateutil.parser import dateutil.parser
import logging import logging
import os import os
import shutil
import sqlite3 import sqlite3
import subprocess import subprocess
@ -61,6 +62,15 @@ def full_rescan(mpd_root):
# Connect to db # Connect to db
db_path = os.path.join(_BLISSIFY_DATA_HOME, "db.sqlite3") db_path = os.path.join(_BLISSIFY_DATA_HOME, "db.sqlite3")
logging.debug("Using DB path: %s." % (db_path,)) logging.debug("Using DB path: %s." % (db_path,))
# Backup database
backup_db_path = "%s.old" % (db_path,)
try:
shutil.copy(db_path, "%s" % (backup_db_path,))
print(("DB is saved as %s. You can remove this file manually " +
"at the end of the proces if you want.") % (backup_db_path,))
except FileNotFoundError:
pass
# Empty database
try: try:
conn = sqlite3.connect(db_path) conn = sqlite3.connect(db_path)
conn.row_factory = sqlite3.Row conn.row_factory = sqlite3.Row