swrap: Implement support for IP_RECVDSTADDR on BSD.
[Samba/wip.git] / python / samba / tdb_util.py
blobd967434e5b852e995fa7da7b6a0b38dd6b82245a
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
25 def tdb_copy(file1, file2):
26 """Copy tdb file using tdbbackup utility and rename it
27 """
28 # Find the location of tdbbackup tool
29 dirs = ["bin", samba.param.bin_dir()] + os.getenv('PATH').split(os.pathsep)
30 for d in dirs:
31 toolpath = os.path.join(d, "tdbbackup")
32 if os.path.exists(toolpath):
33 break
35 tdbbackup_cmd = [toolpath, "-s", ".copy.tdb", file1]
36 status = subprocess.call(tdbbackup_cmd, close_fds=True, shell=False)
38 if status == 0:
39 os.rename("%s.copy.tdb" % file1, file2)
40 else:
41 raise Exception("Error copying %s" % file1)