Skip to content

danmcne/Backup-with-Version-Control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Backup Script with Version Control

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.

Features

  • 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 rsync to 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.

Requirements

  • rsync: The script relies on rsync for file synchronization.
  • uuidgen: Used to generate unique identifiers for versioning.
  • Optional: ssh for remote backups.

Installation

  1. Clone the repository or download the script:
    git clone https://github.com/yourusername/sbackup.sh.git
  2. Make the script executable:
    chmod +x sbackup.sh

Usage

Basic Syntax

./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.

Example 1: Local Backup

To back up /home/user/documents to /mnt/backup:

./sbackup.sh /home/user/documents /mnt/backup

Example 2: Remote Backup

To back up /home/user/documents to a remote machine:

./sbackup.sh /home/user/documents user@remote:/path/to/backup

Example 3: Verbose Mode

Enable verbose mode for more detailed output:

./sbackup.sh -v /home/user/documents /mnt/backup

How It Works

  1. Rsync synchronization: The script uses rsync to synchronize the source directory to the destination directory. Only modified files are copied, optimizing bandwidth and storage.

  2. Versioning: If a file already exists in the destination, rsync moves the older version to an older_versions folder inside the destination. The older version is renamed by appending:

    • A ~YYYY-MM-DD timestamp 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.

Example of Versioned Filename:

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

License

This project is licensed under the MIT License.


Feel free to modify the script to suit your needs. Contributions and improvements are welcome!

Releases

No releases published

Packages

 
 
 

Contributors

Languages