Browse Source

Backup database before running a full rescan operation.

Phyks (Lucas Verney) 5 years ago
parent
commit
71901718ce
1 changed files with 10 additions and 0 deletions
  1. 10
    0
      mpd/server.py

+ 10
- 0
mpd/server.py View File

@@ -10,6 +10,7 @@ import argparse
10 10
 import dateutil.parser
11 11
 import logging
12 12
 import os
13
+import shutil
13 14
 import sqlite3
14 15
 import subprocess
15 16
 
@@ -61,6 +62,15 @@ def full_rescan(mpd_root):
61 62
     # Connect to db
62 63
     db_path = os.path.join(_BLISSIFY_DATA_HOME, "db.sqlite3")
63 64
     logging.debug("Using DB path: %s." % (db_path,))
65
+    # Backup database
66
+    backup_db_path = "%s.old" % (db_path,)
67
+    try:
68
+        shutil.copy(db_path, "%s" % (backup_db_path,))
69
+        print(("DB is saved as %s. You can remove this file manually " +
70
+               "at the end of the proces if you want.") % (backup_db_path,))
71
+    except FileNotFoundError:
72
+        pass
73
+    # Empty database
64 74
     try:
65 75
         conn = sqlite3.connect(db_path)
66 76
         conn.row_factory = sqlite3.Row