Package: rsync-time-machine
Rsync Time Machine 🕰️💾Introducingrsync-time-machine.py- a Python port of thersync-time-backupscript, offering Time Machine-style backups using rsync. It creates incremental backups of files and directories to the destination of your choice. The backups are structured in a way that makes it easy to recover any file at any point in time. 🚀It works on Linux, macOS, and Windows (via WSL or Cygwin). The main advantage over Time Machine is flexibility, as it can backup from/to any filesystem and works on any platform. You can also backup to a Truecrypt drive without any problem. 😃rsync-time-machine.pyis fully tested, has no external dependencies (only Python ≥3.7 🐍), is fully compatible withrsync-time-backup, offers pretty terminal output, and is fully typed! 🎉[ToC]📚:star2: Features:books: Usage:hammer_and_wrench: Installation:bulb: Examples:calendar: Backup Expiration Logic:page_facing_up: Exclusion File:lock: Built-in Lock:gear: Rsync Options:no_entry_sign: No Automatic Backup Expiration:arrows_counterclockwise: How to Restore:star: Featured on:heart: Support and Contributions:star2: Features📁 Each backup is in its own folder named after the current timestamp.🔒 Backup to/from remote destinations over SSH.🔗 Files that haven't changed from one backup to the next are hard-linked to the previous backup, saving space.⚠️ Safety check - the backup will only happen if the destination has explicitly been marked as a backup destination.🔄 Resume feature - if a backup has failed or was interrupted, the tool will resume from there on the next backup.🚫 Exclude file - support for pattern-based exclusion via the--exclude-fromrsync parameter.🧹 Automatically purge old backups based on a configurable expiration strategy.🔗 "latest" symlink that points to the latest successful backup.:books: UsageTo usersync-time-machine.py, you'll need to provide source and destination paths, along with any desired options:rsync-time-machine--helpShows the help message:usage:rsync-time-machine[-h][-pPORT][-iID_RSA][--rsync-get-flags][--rsync-set-flagsRSYNC_SET_FLAGS][--rsync-append-flagsRSYNC_APPEND_FLAGS][--log-dirLOG_DIR][--strategySTRATEGY][--no-auto-expire][--allow-host-only][--exclude-fromEXCLUDE_FROM][-v]src_folderdest_folder[exclusion_file]Ascriptforcreatingandmanagingtime-stampedbackupsusingrsync.

positionalarguments:src_folderSourcefolderforbackup.Format:[USER@HOST:]SOURCEdest_folderDestinationfolderforbackup.Format:[USER@HOST:]DESTINATIONexclusion_filePathtothefilecontainingexcludepatterns.Cannotbeusedtogetherwith`--exclude-from`.

options:-h,--helpshowthishelpmessageandexit-pPORT,--portPORTSSHport.-iID_RSA,--id_rsaID_RSASpecifytheprivatesshkeytouse.--rsync-get-flagsDisplaythedefaultrsyncflagsthatareusedforbackup.IfusingremotedriveoverSSH,--compresswillbeadded.--rsync-set-flagsRSYNC_SET_FLAGSSetthersyncflagsthataregoingtobeusedforbackup.--rsync-append-flagsRSYNC_APPEND_FLAGSAppendthersyncflagsthataregoingtobeusedforbackup.--log-dirLOG_DIRSetthelogfiledirectory.Ifthisflagisset,generatedfileswillnotbemanagedbythescript-inparticulartheywillnotbeautomaticallydeleted.Default:$HOME/.rsync-time-backup--strategySTRATEGYSettheexpirationstrategy.Default:"1:1 30:7365:30"meansafteroneday,keeponebackupperday.After30days,keeponebackupevery7days.After365dayskeeponebackupevery30days.--no-auto-expireDisableautomaticallydeletingbackupswhenoutofspace.Instead,anerrorislogged,andthebackupisaborted.--allow-host-onlyBydefault,thescriptexpectsa'USER@HOST'patternforspecifyingSSHconnections.Whenthisflagisused,itallowsforthe'HOST'patternwithoutaspecifieduser.Thisisusefulifyouwanttouseconfigurationsfromthe`.ssh/config`fileorrelyonthecurrentusername.Note:thisoptionwillnotenforceSSHusage,itonlybroadenstheacceptedinputformats.--exclude-fromEXCLUDE_FROMPathtothefilecontainingexcludepatterns.Alternativetothepositional`exclusion_file`.Nottobeusedwith`exclusion_file`.-v,--verboseEnableverboseoutput.Thiswillslowdownthebackupprocess(insimpletestsby2x).Please refer to the originalrsync-time-backupREADME for a list of options, as they have been preserved in the Python port.:hammer_and_wrench: InstallationTo installrsync-time-machine.py, simply clone the repository:pipinstallrsync-time-machineand use it likersync-time-machine --helpOr just copy the script to your computer:wgethttps://raw.githubusercontent.com/basnijholt/rsync-time-machine.py/main/rsync_time_machine.pyand use it like./rsync_time_machine.py --help:bulb: ExamplesBackup the home folder to backup_drive:./rsync_time_machine.py /home /mnt/backup_driveBackup with exclusion list:./rsync_time_machine.py /home /mnt/backup_drive excluded_patterns.txtFor more examples and detailed usage instructions, please refer to the originalrsync-time-backupREADME.:calendar: Backup Expiration LogicBackup sets are automatically deleted following a simple expiration strategy defined with the--strategyflag. The default strategy is1:1 30:7 365:30. Please see the original README for a detailed explanation.:page_facing_up: Exclusion FileAn optional exclude file can be provided as a third parameter, compatible with the--exclude-fromparameter of rsync.The--exclude-fromoption inrsync-time-machine.pyallows you to exclude specific files or directories from the backup process. You can provide an exclusion file containing patterns for files or directories that should be excluded.📖🔽 Click here to expand the docs on--exclude-from🔽📖Here's how to use the--exclude-fromfeature inrsync-time-machine.py:Create a text file namedexclusion_file.txt(or any other name you prefer) in your preferred location.Add the exclusion patterns to the file, one pattern per line. Patterns can be literal strings, wildcards, or character ranges.Save the file.To use this exclusion file while performing a backup withrsync-time-machine.py, include it as the third positional argument in your command (or with--exclude-from exclusion_file.txt). For example:rsync-time-machine.py/home/mnt/backup_driveexclusion_file.txtIn this example,/homeis the source folder,/mnt/backup_driveis the destination folder, andexclusion_file.txtcontains the exclude patterns.Here's a sampleexclusion_file.txt:+ /home/.fileA
- /home/.*
- /home/junk/In this example:+ /home/.fileA: Include the file.fileAfrom thehomedirectory.- /home/.*: Exclude all hidden files (files starting with a dot) from thehomedirectory.- /home/junk/: Exclude the entirejunkdirectory from thehomedirectory.Remember that the order of patterns matters, as rsync reads the file top-down and acts on the first matching pattern it encounters.Seethis tutorialfor more information.:lock: Built-in LockThe script is designed so that only one backup operation can be active for a given directory, avoiding conflicts.:gear: Rsync OptionsTo display, add, or remove rsync options, use the--rsync-get-flags,--rsync-append-flags, or--rsync-set-flagsoptions.:no_entry_sign: No Automatic Backup ExpirationUse the--no-auto-expireflag to disable the default behavior of purging old backups when out of space.:arrows_counterclockwise: How to RestoreRestoring files from the backup is simple, as the script creates a backup in a regular directory. You can easily copy the files back to the original directory using a command like:rsync -aP /path/to/last/backup/ /path/to/restore/to/Consider using the--dry-runoption to check what exactly is going to be copied. If you want to delete files that exist in the destination but not in the backup, use the--deleteoption. Be extra cautious when using this option to avoid data loss.You can also restore files using any file explorer, including Finder on macOS or the command line.:star: Featured onthe Real Python podcast:Episode 158: Building Python CI With Docker & Applying for a Hacker Initiative Grant @ 00:26:28Y Combinator Hacker News:Python Port of 600 Line Bash Script: rsync-time-machine.py for Rsync Backups(self-posted)Reddit /rpython:Ported a popular (untested) 600+ Line Bash Script 📜 to Python 🐍: Introducing rsync-time-machine.py for Time Machine-Style Backups Using Rsync 🔄⏰(self-posted):heart: Support and ContributionsWe appreciate your feedback and contributions! If you encounter any issues or have suggestions for improvements, please file an issue on the GitHub repository. We also welcome pull requests for bug fixes or new features.Happy backing up! 💾🕰️🎉