Site icon DesignLinux

Zaloha.sh – A Simple Local Directory Synchronizer Script for Linux

Zaloha.sh is a tiny and simple shell script used to synchronize two local directories: a source directory and a backup directory. It employs standard Linux/Unix tools such as find, sort, awk, mkdir, rmdir, cp and rm to support its underlying functionality.

Zaloha obtains information about the directories and files via the find command. Both directories must be available locally i.e mounted to the local file system. It also features reverse-synchronization, and can optionally compare files byte by byte. Besides, it asks users to confirm actions before they are executed.

In this article, you will learn how to install and use zaloha.sh to synchronize two local directories in Linux.

Installing Zaloha.sh in Linux

To install Zaloha.sh, you need to clone its Github repository using the git command-line tool, but before that, you need to install git as shown.

# dnf  install git		# CentOS/RHEL 8/Fedora 22+
# yum install git		# CentOS/RHEL 7/Fedora
$ sudo apt install git		# Ubuntu/Debian

Once git is installed, run the following command to clone the remote repository to your system, move into the local repository, then install the zaloha.sh script in a location in your PATH e.g /usr/bin and make it executable as shown.

$ git clone https://github.com/Fitus/Zaloha.sh.git
$ cd Zaloha.sh/
$ echo $PATH
$ sudo cp Zaloha.sh /usr/bin/zaloha.sh
$ sudo chmod +x /usr/bin/zaloha.sh
Install Zaloha.sh in Linux

Install Zaloha.sh in Linux

Synchronize Two Local Directories in Linux Using Zaloha.sh

Now that zaloha.sh is installed in your PATH, you can run it normally like any other command. You can synchronize two local directories as shown.

$ sudo zaloha.sh --sourceDir="./admin_portal/" --backupDir="/var/www/html/admin_portal/"

After running it, zaloha will analyze the two directories and prepares the commands necessary to synchronize the two directories.

Sync Two Local Directories in Linux

You will be prompted to confirm the actions to be executed: “Execute above-listed copies to /var/www/html/admin_portal/? [Y/y=Yes, other=do nothing, and abort]:”. Answer yes to proceed.

File Synchronize Confirmation

Backup to External/Removable USB Media

You can also backup to a removable media (e.g /media/aaronk/EXT) mounted to the local file system. The destination directory must exist for the command to work, otherwise you will get the error message “Zaloha.sh: <backupDir> is not a directory”.

$ sudo mkdir /media/aaronk/EXT/admin_portal
$ sudo zaloha.sh --sourceDir="./admin_portal/" --backupDir="/media/aaronk/EXT/admin_portal"

Backup Files to USB Device

Backup Changes from Source to Backup Directory

Now make more changes in the source directory, then run zaloha.sh once more to back up the changes in the external disk as shown.

$ mkdir /home/aaronk/admin_portal/plugins
$ mkdir /home/aaronk/admin_portal/images
$ sudo zaloha.sh --sourceDir="/home/aaronk/admin_portal/" --backupDir="/media/aaronk/EXT/admin_portal"

Zaloha.sh will create the new directories in the backup directory and copy any new files from the source as well as highlighted in the following screenshot.

Sync New Changes in Linux

Reverse Synchronize Changes from Backup to Source Directory

Assuming you have made changes in the backup directory to files that already exist in the source directory, you can make the changes reflect in the source directory using the reverse sync feature, enabled using the --renUp option.

$ zaloha.sh --revUp --sourceDir="/home/aaronk/admin_portal/" --backupDir="/media/aaronk/EXT/admin_portal"

Reverse Sync from Backup to Source

Note that any new files or directories created in the backup directory that doesn’t exist in the source directory will also be deleted as indicated in the following screenshot.

Reverse Synchronize Files

You can tell zaloha to follow symbolic links on the source directory using the --followSLinksS option and on the backup directory using the --followSLinksB option.

$ sudo zaloha.sh --followSLinksS  --followSLinksB --sourceDir="./admin_portal/" --backupDir="/var/www/html/admin_portal/"

To view the Zaloha documentation, run the following command.

$ zaloha.sh --help

That’s all for now! Zalohah.sh is a small and simple Bash-based backup script to synchronize two local directories in Linux. Give it a try and share your thoughts with us via the feedback form below.

Sharing is Caring…
Share on FacebookShare on TwitterShare on LinkedinShare on Reddit
Exit mobile version