Skip to content

Instantly share code, notes, and snippets.

@frafra
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frafra/a5e88d68b0851a1b9f1e to your computer and use it in GitHub Desktop.
Save frafra/a5e88d68b0851a1b9f1e to your computer and use it in GitHub Desktop.
Check if there are missing files in your backup (based on filenames)
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright 2014 Francesco Frassinelli
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import collections
import os
import sys
import time
if len(sys.argv) < 3:
print("Usage: %s target dest" % sys.argv[0])
exit(1)
def getfiles(rootdir):
res = collections.defaultdict(list)
for root, subdirs, files in os.walk(rootdir):
for f in files:
res[f].append(os.path.join(root, f))
return res
target = getfiles(sys.argv[1])
dest = getfiles(sys.argv[2])
for f in set(target.keys())-set(dest.keys()):
print("%s: %s" % (f, ", ".join(target[f])))
if len(target[f]) > 1:
for path in target[f]:
print("-"*(len(f)+1)+" %s (%s B)" % (
time.ctime(os.path.getmtime(path)),
os.path.getsize(path)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment