sbackup.sh is a simple and efficient bash script for backing up directories using rsync. It ensures that older versions of files are preserved by appending a timestamp and a unique identifier to each file. The script supports both local and remote backups.
- Backup with versioning: Moves older versions of files to a designated folder (
older_versions), appending a date and a unique 8-character UUID to ensure each version is unique. - Efficient synchronization: Uses
rsyncto efficiently sync files between directories, only copying changes and preserving file attributes. - Support for remote backups: Works seamlessly with local and remote directories.
- Verbose mode: Option to output detailed logs for troubleshooting.
rsync: The script relies onrsyncfor file synchronization.uuidgen: Used to generate unique identifiers for versioning.- Optional:
sshfor remote backups.
- Clone the repository or download the script:
git clone https://github.com/yourusername/sbackup.sh.git
- Make the script executable:
chmod +x sbackup.sh
./sbackup.sh [-v] <source_dir> <dest_dir>source_dir: The directory you want to back up.dest_dir: The destination directory where the files will be copied. This can be a local or remote path.-v: (Optional) Verbose mode for more detailed output.
To back up /home/user/documents to /mnt/backup:
./sbackup.sh /home/user/documents /mnt/backupTo back up /home/user/documents to a remote machine:
./sbackup.sh /home/user/documents user@remote:/path/to/backupEnable verbose mode for more detailed output:
./sbackup.sh -v /home/user/documents /mnt/backup-
Rsync synchronization: The script uses
rsyncto synchronize the source directory to the destination directory. Only modified files are copied, optimizing bandwidth and storage. -
Versioning: If a file already exists in the destination,
rsyncmoves the older version to anolder_versionsfolder inside the destination. The older version is renamed by appending:- A
~YYYY-MM-DDtimestamp representing the date of the sync. - A unique 8-character ID generated by
uuidgen.
This ensures that each older version is unique, even if the same file is backed up multiple times a day.
- A
If the original file is example.txt, and it is moved to the older_versions folder, the new file might look like:
example.txt~2024-10-01-abcdef12
This project is licensed under the MIT License.
Feel free to modify the script to suit your needs. Contributions and improvements are welcome!