Commit e7252d6d authored by ben's avatar ben

Various changes to switch to new include/exclude syntax


git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup@39 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
parent f7a6f269
#!/usr/bin/env python
#
# rdiff-backup -- Mirror files while keeping incremental changes
# Version 0.7.1 released March 25, 2002
# Version 0.7.2 released April 30, 2002
# Copyright (C) 2001, 2002 Ben Escoto <bescoto@stanford.edu>
#
# This program is licensed under the GNU General Public License (GPL).
......
......@@ -8,7 +8,7 @@ import re, os
class Globals:
# The current version of rdiff-backup
version = "0.7.1"
version = "0.7.2"
# If this is set, use this value in seconds as the current time
# instead of reading it from the clock.
......@@ -45,26 +45,9 @@ class Globals:
# If true, try to reset the atimes of the source partition.
preserve_atime = None
# This is a list of compiled regular expressions. If one of them
# matches a file in the source area, do not process that file.
exclude_regexps = []
# Another list of compiled regexps; this time the file is excluded
# if it matches something in the destination area.
exclude_mirror_regexps = []
# If this is true, rdiff-backup will exclude any dev files it
# sees, in the same way it excludes files matching the exclude
# regexps.
exclude_device_files = None
# This will be set as soon as the LocalConnection class loads
local_connection = None
# If this is true, instead of processing whole directory, just
# examine files read in from standard input.
include_from_stdin = None
# All connections should be added to the following list, so
# further global changes can be propagated to the remote systems.
# The first element should be Globals.local_connection. For a
......@@ -138,12 +121,16 @@ class Globals:
# Increments based on files whose names match this
# case-insensitive regular expression won't be compressed (applies
# to .snapshots and .diffs). The second below is the compiled
# version of the first.
# to .snapshots and .diffs). The second below will be the
# compiled version of the first.
no_compression_regexp_string = ".*\\.(gz|z|bz|bz2|tgz|zip|rpm|deb|" \
"jpg|gif|png|mp3|ogg|avi|wmv|mpeg|mpg|rm|mov)$"
no_compression_regexp = None
# On the reader and writer connections, the following will be
# replaced by the source and mirror Select objects respectively.
select_source, select_mirror = None, None
def get(cls, name):
"""Return the value of something in this class"""
return cls.__dict__[name]
......@@ -181,19 +168,6 @@ class Globals:
cls.__dict__[name][key] = val
set_dict_val = classmethod(set_dict_val)
def add_regexp(cls, regstr, mirror=None):
"""Add a regular expression to the exclude list"""
for conn in Globals.connections:
conn.Globals.add_regexp_local(regstr, mirror)
add_regexp = classmethod(add_regexp)
def add_regexp_local(cls, regstr, mirror):
"""Add the regex only to the local Globals class"""
compiled = re.compile(regstr)
if mirror: Globals.exclude_mirror_regexps.append(compiled)
else: Globals.exclude_regexps.append(compiled)
add_regexp_local = classmethod(add_regexp_local)
def postset_regexp(cls, name, re_string, flags = None):
"""Compile re_string on all existing connections, set to name"""
for conn in Globals.connections:
......@@ -205,3 +179,13 @@ class Globals:
if flags: cls.__dict__[name] = re.compile(re_string, flags)
else: cls.__dict__[name] = re.compile(re_string)
postset_regexp_local = classmethod(postset_regexp_local)
def set_select(cls, source, dsrpath, tuplelist):
"""Initialize select object using tuplelist"""
if source:
cls.select_source = Select(dsrpath)
cls.select_source.ParseArgs(tuplelist)
else:
cls.select_mirror = Select(dsrpath)
cls.select_mirror.ParseArgs(tuplelist)
set_select = classmethod(set_select)
#!/usr/bin/env python
#
# rdiff-backup -- Mirror files while keeping incremental changes
# Version 0.7.1 released March 25, 2002
# Version 0.7.2 released April 30, 2002
# Copyright (C) 2001, 2002 Ben Escoto <bescoto@stanford.edu>
#
# This program is licensed under the GNU General Public License (GPL).
......
......@@ -13,22 +13,29 @@ class Main:
self.action = None
self.remote_cmd, self.remote_schema = None, None
self.force = None
self.exclude_regstrs = ["/proc"]
self.exclude_mirror_regstrs = []
self.select_opts, self.select_mirror_opts = [], []
def parse_cmdlineoptions(self):
"""Parse argument list and set global preferences"""
try: optlist, self.args = getopt.getopt(sys.argv[1:], "blmv:Vs",
["backup-mode", "version", "verbosity=", "exclude=",
"exclude-mirror=", "server", "test-server",
"remote-cmd=", "mirror-only", "force",
"change-source-perms", "list-increments",
"remove-older-than=", "remote-schema=",
"include-from-stdin", "terminal-verbosity=",
"exclude-device-files", "resume", "no-resume",
"resume-window=", "windows-time-format",
"checkpoint-interval=", "no-hard-links", "current-time=",
"no-compression", "no-compression-regexp="])
def sel_fl(filename):
"""Helper function for including/excluding filelists below"""
try: return open(filename, "r")
except IOError: Log.FatalError("Error opening file %s" % filename)
try: optlist, self.args = getopt.getopt(sys.argv[1:], "blmsv:V",
["backup-mode", "change-source-perms",
"checkpoint-interval=", "current-time=", "exclude=",
"exclude-device-files", "exclude-filelist=",
"exclude-filelist-stdin", "exclude-mirror=",
"exclude-regexp=", "force", "include=",
"include-filelist=", "include-filelist-stdin",
"include-regexp=", "list-increments", "mirror-only",
"no-compression", "no-compression-regexp=",
"no-hard-links", "no-resume", "remote-cmd=",
"remote-schema=", "remove-older-than=", "resume",
"resume-window=", "server", "terminal-verbosity=",
"test-server", "verbosity", "version",
"windows-time-format"])
except getopt.error:
self.commandline_error("Error parsing commandline options")
......@@ -40,13 +47,24 @@ class Main:
Globals.set_integer('checkpoint_interval', arg)
elif opt == "--current-time":
Globals.set_integer('current_time', arg)
elif opt == "--exclude": self.exclude_regstrs.append(arg)
elif opt == "--exclude": self.select_opts.append((opt, arg))
elif opt == "--exclude-device-files":
Globals.set('exclude_device_files', 1)
self.select_opts.append((opt, arg))
elif opt == "--exclude-filelist":
self.select_opts.append((opt, (arg, sel_fl(arg))))
elif opt == "--exclude-filelist-stdin":
self.select_opts.append((opt, ("standard input", sys.stdin)))
elif opt == "--exclude-mirror":
self.exclude_mirror_regstrs.append(arg)
self.select_mirror_opts.append(("--exclude", arg))
elif opt == "--exclude-regexp": self.select_opts.append((opt, arg))
elif opt == "--force": self.force = 1
elif opt == "--include-from-stdin": Globals.include_from_stdin = 1
elif opt == "--include": self.select_opts.append((opt, arg))
elif opt == "--include-filelist":
self.select_opts.append((opt, (arg, sel_fl(arg))))
elif opt == "--include-filelist-stdin":
self.select_opts.append((opt, ("standard input", sys.stdin)))
elif opt == "--include-regexp":
self.select_opts.append((opt, arg))
elif opt == "-l" or opt == "--list-increments":
self.action = "list-increments"
elif opt == "-m" or opt == "--mirror-only": self.action = "mirror"
......@@ -116,10 +134,10 @@ class Main:
for rp in rps: rp.setdata() # Update with userinfo
os.umask(077)
for regex_string in self.exclude_regstrs:
Globals.add_regexp(regex_string, None)
for regex_string in self.exclude_mirror_regstrs:
Globals.add_regexp(regex_string, 1)
rps[0].conn.Globals.set_select(1, rps[0], self.select_opts)
if len(rps) == 2:
rps[1].conn.Globals.set_select(None, rps[1],
self.select_mirror_opts)
Globals.postset_regexp('no_compression_regexp',
Globals.no_compression_regexp_string, re.I)
......@@ -217,9 +235,6 @@ rdiff-backup with the --force option.""" % rpout.path)
except os.error:
Log.FatalError("Unable to create directory %s" % rpout.path)
if not self.datadir.lstat(): self.datadir.mkdir()
Globals.add_regexp(self.datadir.path, 1)
Globals.add_regexp(rpin.append("rdiff-backup-data").path, None)
if Log.verbosity > 0:
Log.open_logfile(self.datadir.append("backup.log"))
self.backup_warn_if_infinite_regress(rpin, rpout)
......@@ -334,7 +349,6 @@ Try restoring from an increment file (the filenames look like
else: Log.FatalError("Unable to find rdiff-backup-data dir")
Globals.rbdir = self.datadir = datadirrp
Globals.add_regexp(self.datadir.path, 1)
rootrp = RPath(rpin.conn, "/".join(pathcomps[:i]))
if not rootrp.lstat():
Log.FatalError("Root of mirror area %s does not exist" %
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment