Make sqlite backup and restore commands work (closes #69607)

  • gzip deletes the uncompressed file, and we don't want that
  • compressed dumps are stored as 'system', so let's not insist on a .gz suffix when restoring them
authorJulien Cristau <julien.cristau@logilab.fr>
changeset37d856bfd6f3
branchstable
phasepublic
hiddenno
parent revision#4892213f686c update changelog
child revision#c3cf9b35da61 [sqlserver2005] accept different types of arguments in sql_add_limit_offset (closes #70253)
files modified by this revision
ChangeLog
sqlite.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1309364263 -7200
# Wed Jun 29 18:17:43 2011 +0200
# Branch stable
# Node ID 37d856bfd6f3527b33dc8e7ebe07b9f46fd4da78
# Parent 4892213f686c87c7d66eeff24886fc84dfea3610
Make sqlite backup and restore commands work (closes #69607)

- gzip deletes the uncompressed file, and we don't want that
- compressed dumps are stored as 'system', so let's not insist on a .gz
suffix when restoring them

diff --git a/ChangeLog b/ChangeLog
@@ -1,10 +1,11 @@
1  Changelog for logilab database package
2  ======================================
3 
4  --
5      * [fti] exclude numbers from stop words in fti parser (closes: #69471)
6 +    * fix backup/restore commands for sqlite backend (closes: #69607)
7 
8  2011-06-09  --  1.6.0
9      * new CAST function
10 
11      * new methods on db_helpers to support regexp-based pattern
diff --git a/sqlite.py b/sqlite.py
@@ -234,19 +234,16 @@
12      alter_column_support = False
13 
14      def backup_commands(self, backupfile, keepownership=True,
15                          dbname=None, dbhost=None, dbport=None, dbuser=None):
16          dbname = dbname or self.dbname
17 -        return [['gzip', dbname], ['mv', dbname + '.gz', backupfile]]
18 +        return ['gzip -c %s > %s' % (dbname, backupfile)]
19 
20      def restore_commands(self, backupfile, keepownership=True, drop=True,
21                           dbname=None, dbhost=None, dbport=None, dbuser=None,
22                           dbencoding=None):
23 -        gunziped, ext = os.path.splitext(backupfile)
24 -        msg = 'extension is %s but .gz or .z expected. Are you sure this is a sqlite dump?' % ext.lower()
25 -        assert ext.lower() in ('.gz', '.z'), msg # else gunzip will fail anyway
26 -        return [['gunzip', backupfile], ['mv', gunziped, dbname or self.dbname]]
27 +        return ['zcat %s > %s' % (backupfile, dbname or self.dbname)]
28 
29      def sql_create_index(self, table, column, unique=False):
30          idx = self._index_name(table, column, unique)
31          if unique:
32              return 'CREATE UNIQUE INDEX %s ON %s(%s);' % (idx, table, column)