Skip to content

moijafcor/automysqlbackup-purger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

automysqlbackup-purger

Purge old automysqlbackup files from a backup directory tree based on a configurable retention policy derived from the daily/weekly/monthly directory structure.

Requirements

Python 3.8 or later. No external dependencies — stdlib only.

Installation

# Run directly
python3 automysqlbackup_purger.py /path/to/automysqlbackup

# Or install via pip (adds automysqlbackup-purger to PATH)
pip install .

Retention policy

Backup type Default retention Flag
monthly 730 days (2 years) --retention-monthly
weekly 180 days (6 months) --retention-weekly
daily 30 days (1 month) --retention-daily
other 365 days (1 year) --retention-other

Retention type is determined by path components, so a database named bi-weekly_reports will not accidentally match weekly.

Usage

Dry run (default — shows what would be deleted, makes no changes):

python3 automysqlbackup_purger.py /path/to/automysqlbackup

Live run (actually deletes expired files):

python3 automysqlbackup_purger.py /path/to/automysqlbackup --no-dry-run

Archive mode (moves expired files to a directory instead of deleting):

python3 automysqlbackup_purger.py /path/to/automysqlbackup \
    --archive-dir /mnt/cold-storage/expired --no-dry-run

Override retention and prune empty directories:

python3 automysqlbackup_purger.py /path/to/automysqlbackup \
    --retention-daily 14 --retention-weekly 90 \
    --prune-empty-dirs --no-dry-run

Point the script at the automysqlbackup subtree, not the storage root. Files are already .sql.gz — re-compression gains nothing and breaks per-file restorability.

Options

Flag Default Description
path (required) automysqlbackup directory to scan
--patterns *.sql.gz *.sql File patterns to match
--exclude-patterns Additional filename patterns to skip
--exclude-dirs Directory names (or fnmatch patterns) to skip, matched against path components
--archive-dir Move expired files here instead of deleting
--no-dry-run Actually delete/move files (default is a safe dry run)
--prune-empty-dirs Remove empty directories after purging (reported in dry-run)
--follow-symlinks Follow symlinks when walking; symlinked files are skipped by default
--retention-daily 30 Retention for daily backups (days)
--retention-weekly 180 Retention for weekly backups (days)
--retention-monthly 730 Retention for monthly backups (days)
--retention-other 365 Retention for unclassified backups (days)
-v / --verbose Enable debug output
-q / --quiet Suppress all output except errors
--version Show version and exit

Always-skipped files

Regardless of age, the following are never purged: stat, .DS_Store, Thumbs.db, *.log, *.log.gz, *.tmp, *.meta.

Exit codes

Code Meaning
0 Success
1 Fatal error (bad path, archive check failed)
2 Completed with per-file errors

Running tests

python3 -m pytest
# or
python3 -m unittest discover tests

Related projects

About

Purge old automysqlbackup files from a backup directory tree based on retention policy derived from the daily/weekly/monthly directory structure.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages