9
9
# Subversion is a tool for revision control.
10
# See http://subversion.tigris.org for more information.
10
# See http://subversion.apache.org for more information.
12
12
# ====================================================================
13
# Copyright (c) 2000-2009 CollabNet. All rights reserved.
15
# This software is licensed as described in the file COPYING, which
16
# you should have received as part of this distribution. The terms
17
# are also available at http://subversion.tigris.org/license-1.html.
18
# If newer versions of this license are posted there, you may use a
19
# newer version instead, at your option.
21
# This software consists of voluntary contributions made by many
22
# individuals. For exact contribution history, see the revision
23
# history and logs, available at http://subversion.tigris.org/.
13
# Licensed to the Apache Software Foundation (ASF) under one
14
# or more contributor license agreements. See the NOTICE file
15
# distributed with this work for additional information
16
# regarding copyright ownership. The ASF licenses this file
17
# to you under the Apache License, Version 2.0 (the
18
# "License"); you may not use this file except in compliance
19
# with the License. You may obtain a copy of the License at
21
# http://www.apache.org/licenses/LICENSE-2.0
23
# Unless required by applicable law or agreed to in writing,
24
# software distributed under the License is distributed on an
25
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
26
# KIND, either express or implied. See the License for the
27
# specific language governing permissions and limitations
24
29
# ====================================================================
26
# $HeadURL: http://svn.apache.org/repos/asf/subversion/branches/1.6.x/tools/backup/hot-backup.py.in $
27
# $LastChangedDate: 2009-01-25 06:09:04 +0000 (Sun, 25 Jan 2009) $
28
# $LastChangedBy: arfrever $
29
# $LastChangedRevision: 875528 $
31
# $HeadURL: http://svn.apache.org/repos/asf/subversion/branches/1.7.x/tools/backup/hot-backup.py.in $
32
# $LastChangedDate: 2010-08-20 04:30:52 +0000 (Fri, 20 Aug 2010) $
33
# $LastChangedBy: cmpilato $
34
# $LastChangedRevision: 987379 $
31
36
######################################################################
50
55
'bz2' : ".tar.bz2",
54
60
# Chmod recursively on a whole subtree
55
61
def chmod_tree(path, mode, mask):
56
def visit(arg, dirname, names):
59
fullname = os.path.join(dirname, name)
62
for dirpath, dirs, files in os.walk(path):
63
for name in dirs + files:
64
fullname = os.path.join(dirpath, name)
60
65
if not os.path.islink(fullname):
61
66
new_mode = (os.stat(fullname)[stat.ST_MODE] & ~mask) | mode
62
67
os.chmod(fullname, new_mode)
63
os.path.walk(path, visit, (mode, mask))
65
69
# For clearing away read-only directories
66
70
def safe_rmtree(dirname, retry=0):
99
103
--archive-type=FMT Create an archive of the backup. FMT can be one of:
100
bz2 : Creates a bzip2 compressed tar file.
101
gz : Creates a gzip compressed tar file.
102
zip : Creates a compressed zip file.
104
bz2 : Creates a bzip2 compressed tar file.
105
gz : Creates a gzip compressed tar file.
106
zip : Creates a compressed zip file.
107
zip64: Creates a zip64 file (can be > 2GB).
103
108
--num-backups=N Number of prior backups to keep around (0 to keep all).
109
--verify Verify the backup.
104
110
--help -h Print this help message and exit.
106
112
""" % (scriptname,))
274
### Step 4: Verify the hotcopy
276
print("Verifying backup...")
277
err_code = subprocess.call([svnadmin, "verify", "--quiet", backup_subdir])
279
sys.stderr.write("Backup verification failed.\n")
265
### Step 4: Make an archive of the backup if required.
285
### Step 5: Make an archive of the backup if required.
267
287
archive_path = backup_subdir + archive_map[archive_type]
281
301
err_msg = "Tar failed: " + str(e)
284
elif archive_type == 'zip':
304
elif archive_type == 'zip' or archive_type == 'zip64':
288
def add_to_zip(baton, dirname, names):
290
root = os.path.join(baton[1], '')
308
def add_to_zip(zp, root, dirname, names):
309
root = os.path.join(root, '')
292
311
for file in names:
293
312
path = os.path.join(dirname, file)
294
313
if os.path.isfile(path):
295
314
zp.write(path, path[len(root):])
296
315
elif os.path.isdir(path) and os.path.islink(path):
297
os.path.walk(path, add_to_zip, (zp, path))
316
for dirpath, dirs, files in os.walk(path):
317
add_to_zip(zp, path, dirpath, dirs + files)
299
zp = zipfile.ZipFile(archive_path, 'w', zipfile.ZIP_DEFLATED)
300
os.path.walk(backup_subdir, add_to_zip, (zp, backup_dir))
319
zp = zipfile.ZipFile(archive_path, 'w', zipfile.ZIP_DEFLATED, archive_type == 'zip64')
320
for dirpath, dirs, files in os.walk(backup_subdir):
321
add_to_zip(zp, backup_dir, dirpath, dirs + files)
302
323
except ImportError, e:
303
324
err_msg = "Import failed: " + str(e)
315
336
print("Archive created, removing backup '" + backup_subdir + "'...")
316
337
safe_rmtree(backup_subdir, 1)
318
### Step 5: finally, remove all repository backups other than the last
339
### Step 6: finally, remove all repository backups other than the last
321
342
if num_backups > 0: