1 # Unix SMB/CIFS implementation.
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/>.
26 def tdb_copy(file1
, file2
, readonly
=False):
27 """Copy tdb file using tdbbackup utility and rename it
29 # Find the location of tdbbackup tool
30 dirs
= ["bin", samba
.param
.bin_dir()] + os
.getenv('PATH').split(os
.pathsep
)
32 toolpath
= os
.path
.join(d
, "tdbbackup")
33 if os
.path
.exists(toolpath
):
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
]
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
)