tests/gkdi: Remove implicit clock skew offset
[Samba.git] / python / samba / tdb_util.py
blob99b6e02e03f5e6659e1f0b148a10503e419e1712
1 # Unix SMB/CIFS implementation.
2 # tdb util helpers
4 # Copyright (C) Kai Blin <kai@samba.org> 2011
5 # Copyright (C) Amitay Isaacs <amitay@gmail.com> 2011
6 # Copyright (C) Andrew Bartlett <abartlet@samba.org> 2013
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 import samba
22 import subprocess
23 import os
26 def tdb_copy(file1, file2, readonly=False):
27 """Copy tdb file using tdbbackup utility and rename it
28 """
29 # Find the location of tdbbackup tool
30 dirs = ["bin", samba.param.bin_dir()] + os.getenv('PATH').split(os.pathsep)
31 for d in dirs:
32 toolpath = os.path.join(d, "tdbbackup")
33 if os.path.exists(toolpath):
34 break
35 else:
36 # we did not find a path to tdbbackup
37 raise FileNotFoundError(2, "could not find tdbbackup tool: "
38 "is tdb-tools installed?")
40 tdbbackup_cmd = [toolpath, "-s", ".copy.tdb", file1]
41 if readonly:
42 tdbbackup_cmd.append("-r")
44 status = subprocess.check_call(tdbbackup_cmd, close_fds=True, shell=False)
46 os.rename("%s.copy.tdb" % file1, file2)