示例#1
0
#!/usr/bin/env python

import hashdeep
import metadata
import os.path
import pattern
import sys

if __name__ == "__main__":
    if len(sys.argv) != 4:
        print "usage: %s rootdir patterns_file metadata_file" % sys.argv[0]
        sys.exit(1)

    rootdir = os.path.normpath(sys.argv[1])

    patterns_file = open(sys.argv[2])
    patterns = pattern.parse_pattern_file(patterns_file)
    pathlist = pattern.assemble_paths(rootdir, patterns)

    digests = hashdeep.compute_digests(rootdir, pathlist.filenames)
    backup_metadata = metadata.get_backup_metadata(rootdir=rootdir,
                                                   files=pathlist.filenames,
                                                   symlinks=pathlist.symlinks,
                                                   directories=pathlist.directories,
                                                   digest_map=digests)

    with open(sys.argv[3], "w") as metadata_file:
        metadata.write_backup_metadata(metadata_file, backup_metadata)
示例#2
0
        new_node = get_symlink_node(rootdir, linkname, uid_map, gid_map)
        dir_node.children[basename] = new_node

    # Step 3: insert the files into the directory tree
    for filename in files:
        dirname, basename = os.path.split(filename)
        # Navigate to the right part in the directory tree
        dir_node = find_directory_in_tree(root_node, dirname)
        # Insert the file node
        new_node = get_file_node(rootdir, filename, digest_map, uid_map, gid_map)
        dir_node.children[basename] = new_node

    return root_node


if __name__ == "__main__":
    import collections
    import pattern
    import StringIO
    rootdir = '/home/madars/Documents/projects/go-backup'
    patterns_file = StringIO.StringIO("+ /\n")
    patterns = pattern.parse_pattern_file(patterns_file)
    res  = pattern.assemble_paths(rootdir, patterns)
    digest_map = collections.defaultdict(lambda : 'demo')
    uid_map = utils.get_uid_name_map()
    gid_map = utils.get_gid_name_map()
    tree = get_metadata_tree(rootdir, res.filenames, res.symlinks, res.directories,
                             digest_map, uid_map, gid_map)
    import json
    print json.dumps(tree, indent=2)