dirsnapshot
Description
Report differences between a directory and a previous snapshot of the same directory.
This works very similar to dircmp but it is designed to be used with a directory that is being monitored instead of comparing two existing directories.
This module can be run as a standalone CLI app as dirsnap or included in your project as a package.
Usage
from dirsnapshot import DirDiff, create_snapshot
# snapshot a directory
create_snapshot("/Users/user/Desktop", "/Users/user/Desktop/Desktop.snapshot")
# do some work
...
# compare the current state of the director to the snapshot
dirdiff = DirDiff("/Users/user/Desktop/Desktop.snapshot", "/Users/user/Desktop")
# print report to stdout
dirdiff.report()
# or print report to json
print(dirdiff.json())
Installation
pip install dirsnapshot
CLI
Installing the dirsnapshot package will install a command line tool called dirsnap that can be used to create snapshots of directories and compare a directory to an existing snapshot.
usage: dirsnap [-h] [--json] [--snapshot DIRECTORY SNAPSHOT_FILE]
[--diff SNAPSHOT_A DIRECTORY_OR_SNAPSHOT_B]
[--descr DESCRIPTION] [--identical] [--ignore REGEX]
[--no-walk]
Compare a directory to a previously saved snapshot or compare two directory
snapshots. You must specify one of --snapshot or --diff. Will show files
added/removed/modified. Files are considered modified if any of mode, uid,
gid, size, or mtime are different.
options:
-h, --help show this help message and exit
--json, -j Output as JSON
--snapshot DIRECTORY SNAPSHOT_FILE, -s DIRECTORY SNAPSHOT_FILE
Create snapshot of DIRECTORY at SNAPSHOT_FILE
--diff SNAPSHOT_A DIRECTORY_OR_SNAPSHOT_B
Diff SNAPSHOT_A and DIRECTORY_OR_SNAPSHOT_B
--descr DESCRIPTION, -d DESCRIPTION
Optional description of snapshot to store with
snapshot for use with --snapshot.
--identical, -I Include identical files in report (always included
with --json)
--ignore REGEX, -i REGEX
Ignore files matching REGEX
--no-walk Don't walk directories
For example:
$ dirsnap --snapshot ~/Desktop/export before.snapshot
Creating snapshot of '/Users/username/Desktop/export' at 'before.snapshot'
Snapshot created at 'before.snapshot'
$ touch ~/Desktop/export/IMG_4548.jpg
$ rm ~/Desktop/export/IMG_4547.jpg
$ touch ~/Desktop/export/new_file.jpg
$ dirsnap --diff before.snapshot ~/Desktop/export
diff '/Users/username/Desktop/export' 2022-06-05T18:38:11.189886 (Snapshot created at 2022-06-05T18:38:11.189886) vs 2022-06-05T18:39:07.225374 (Snapshot created at 2022-06-05T18:39:07.225374)
Added:
/Users/username/Desktop/export/new_file.jpg
Removed:
/Users/username/Desktop/export/IMG_4547.jpg
Modified:
/Users/username/Desktop/export/IMG_4548.jpg
File Comparison
During the diff comparison, files are considered equal if all properties of the file are equal. Currently, the properties checked are: is_file, is_dir, mode, uid, gid, size, mtime. If any of these properties are different, the file is considered modified.
File Format
The snapshot database file is a standard SQLite database. The current schema is:
CREATE TABLE snapshot (
path TEXT,
is_dir INTEGER,
is_file INTEGER,
st_mode INTEGER,
st_uid INTEGER,
st_gid INTEGER,
st_size INTEGER,
st_mtime INTEGER,
user_data BLOB);
CREATE TABLE _metadata (
description TEXT, source TEXT, version TEXT, created_at DATETIME);
CREATE TABLE about (
description TEXT, directory TEXT, datetime DATETIME);
CREATE INDEX snapshot_path_index ON snapshot (path);
You should not need access the database directly however, as the DirSnapshot class provides methods to access the necessary information abstracted from the actual database schema.
Dependencies
No dependencies! This is a pure Python module that uses only the standard Python libraries.
Metadata
Release files for dirsnapshot 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| dirsnapshot-0.5.0.tar.gz | 10.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dirsnapshot-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.3 kB
Release files / dirsnapshot-0.5.0.tar.gz
| Download URL | dirsnapshot-0.5.0.tar.gz |
|---|---|
| Size | 10.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d74905e55d6ab0e37ef1c1a5b1c390a81345a562c1e3ad97606ba8ad393a717d
|
|
BLAKE2b-256 checksum How to use checksums |
696c6c945d67cb2667491fdd9d7f7a1d6196dca66d8eefb55d742c78785c26cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.10.2 Darwin/19.6.0
|
Release files / dirsnapshot-0.5.0-py3-none-any.whl
| Download URL | dirsnapshot-0.5.0-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
da41644747a7589a2e83f5ccde4c156f0e4435cef9e81890464478459d3ef143
|
|
BLAKE2b-256 checksum How to use checksums |
3aa43149635eb6be28c336744f97cf052f4338e3af17f7e731fae09b59b55534
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.10.2 Darwin/19.6.0
|
Security for dirsnapshot 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.