commit - 49b405563aee486d202e70daf3e3e8b9e7962b7f
commit + c0872132851606646d12af51346ff0e612753862
blob - 45a6222f6b752b22c69e8dfc40ac643c95025c23
blob + cb316531820dbe7e8b830515d48eb65045e2d921
--- yabitrot
+++ yabitrot
"""
Author : Vincent <vincent.delft@gmail.com>
-Version : 0.4
+Version : 0.4.2
Licence : BSD
Require : python >= 3.6
use sqlite3 DB embedded with python package
Developed on: OpenBSD
Tested on : OpenBSD 6.4, Windows 10, osx 10.14
-Description : This tool allow you to calculate a checksum for each files in the target folder
- Those values are stored in an sqlite DB at the root of your targetted folder
+Description : This tool allow you to calculate a check-sum for each files in the target folder
+ Those values are stored in an sqlite DB at the root of your target folder
This program use INODE as key instead of filename, so it can manage hardlinks
- Since that, the scrip does never go outside the targetted filesystem
+ Since that, the scrip does never go outside the target filesystem
it works on openBSD, but should work on any systems (OSX, Windows and Linux)
Typically, you must perform a first scan of the folder you want:
LOGFILE = ""
DRY_RUN = False
DB_FILE_NAME = ".cksum.db"
-BIGFILE_TTS = 10 # number of seconds after which the chksum informs (if verbose) that he is working on a big file
+BIGFILE_TTS = 10 # number of seconds after which the cksum informs (if verbose) that he is working on a big file
def log(text):
crc += zlib.adler32(d)
d = f.read(chunk_size)
if VERBOSE > 0 and time.time() - localtts > BIGFILE_TTS:
- # for pur information, we log the big consumers
+ # only for information, we log the big consumers
log("big file: %s, inode: %s, size: %.2f MB, %s" % (status, osstats.st_ino, osstats.st_size / 1024 / 1024, path))
localtts = time.time()
except OSError as ex:
for excl_patt in excludes:
if fnmatch.fnmatch(fpath, excl_patt):
to_skip = True
+ if not os.path.isfile(fpath):
+ to_skip = True
if to_skip:
if VERBOSE > 0:
log("Based on exclude rules, we skip: %s" % fpath)
class CRCDB:
"""The DB class with 2 tables: cksum and params.
- cksum is the main DB where we store indes and associated chckesums
+ cksum is the main DB where we store inodes and associated cksums
params is a key-pair values table. Currently we store:
- rootpath: the path from where we perform an anlysis
+ rootpath: the path from where we perform an analysis
filesystem id: the id of the targeted filesystem
"""
def __init__(self, fpathname, commitlimit=30):
def analyze(rootpath, excludes=[]):
- """ananlyze rootath and all sub-folders.
- if a DB exists, it compare the checksum of the associated inode with what we have in the DB for this inode
- if a DB does not exists it store the checksum associated to the inode
+ """analyze rootath and all sub-folders.
+ if a DB exists, it compare the cksum of the associated inode with what we have in the DB for this inode
+ if a DB does not exists it store the check-sum associated to the inode
"""
dbpath = os.path.join(rootpath, DB_FILE_NAME)
DB = CRCDB(dbpath, COMMIT_LIMIT)
log("bit ERROR for file %s" % (fpath))
log(" Previous:")
log(" scan was on %s" % time.strftime("%c", time.localtime(db_rec[2])))
- log(" checksum was: %s" % db_rec[1])
+ log(" cksum was: %s" % db_rec[1])
log(" mtime was: %s" % time.strftime("%c", time.localtime(db_rec[0])))
log(" Current:")
log(" scan on %s" % time.strftime("%c", time.localtime(BATCHID)))
- log(" checksum is: %s" % cksum['crc'])
+ log(" cksum is: %s" % cksum['crc'])
log(" mtime is: %s" % time.strftime("%c", time.localtime(osstats.st_mtime)))
counter_biterror += 1
if cksum and cksum['crc']:
log("%s files added" % counter_added)
log("%s files updates" % counter_update)
log("%s files error" % counter_biterror)
- log("%s files analysed in %.2f sec, %.3f GB" % (counter, time.time() - BATCHID, total_size / 1024 / 1024 / 1024))
+ log("%s files analyzed in %.2f sec, %.3f GB" % (counter, time.time() - BATCHID, total_size / 1024 / 1024 / 1024))
log("%s entries in the DB" % records)
if os.name == 'posix' and not DRY_RUN:
os.chmod(dbpath, stat.S_IRUSR | stat.S_IWUSR)
def force_db(fpath, rootpath, excludes=[]):
- """This udate the DB record for this inode"""
+ """This update the DB record for this inode"""
dbpath = os.path.join(rootpath, DB_FILE_NAME)
DB = CRCDB(dbpath, COMMIT_LIMIT)
log("DB stored on: %s" % (dbpath))
return 2
stats = get_cksum(fpath, osstats, "update")
DB.update_rec(osstats.st_ino, stats)
- log("checkcum calculated and stored in the DB")
+ log("check-sum calculated and stored in the DB")
DB.close()
return 0
help='number of DB actions before committing them. Default is %s' % COMMIT_LIMIT)
parser.add_argument(
'-p', '--path', type=str, default='.',
- help='Path to analyse. Default is "."')
+ help='Path to analyze. Default is "."')
parser.add_argument(
'-e', '--exclude', type=str, default='',
help='file types to exclude with the fnmath format. For example *.core,*.tmp. Default is ""')
help='perform the task, but do not update the DB')
parser.add_argument(
'-L', '--log', type=str, default='',
- help='put mesage in the log instead to stdout')
+ help='put message in the log instead to stdout')
parser.add_argument(
'-f', '--force', type=str, default='',
- help='Force checksum for a specific file')
+ help='Force check-sum for a specific file')
args = parser.parse_args()
path = args.path
if args.log: