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

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

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

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

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

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.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide
The Complete Linux System Administrator Bundle
Become an Ethical Hacker Bonus Bundle

You may also like...

10 Responses

  1. Jens says:

    Aaron,

    You seem to have had problems with getting REV.NEW to work: The option --revNew must be given and the file to be REV.NEW-ed must be younger than the last run of Zaloha.sh (= implies that it was created directly in the backup directory).

    If the file is older, then it will be REMOVE-ed, as this implies that it must have existed in the source directory before and somebody removed it from the source directory …

  2. Jens says:

    Add rsync comparison: Clearly Rsync is a program with 20 years history, a de-facto standard, more feature-rich, network-capable and its delta-transfer algorithm has been a landmark in IT. However, this program has the following strong points (besides being very small):

    1) It has the interactivity (execute only after user’s confirmation) plus finer information about the actions. E.g. write of a new file is NEW and the update of an existing file is UPDATE. If you use the --color option, NEW will display black/white (less risky operation) and UPDATE will display red (overwriting = more risky operation = more attention needed). I am not aware that rsync would give you that level of detail.

    2) rsync is memory-constrained as it builds its file lists in memory. Problems have been reported with huge directory trees. This script builds and processes its file lists as CSV files (= not memory-constrained).

    3) it has been reported that Rsync is slower than cp when acting locally. This is caused by the fact that rsync has a checksum-computing function built-in that is active even when copying locally. This program invokes the operating system’s cp command directly.

    4) integrations with other systems, needed changes, etc: a shell script has certain advantages over a binary program

  3. Aamir Khan says:

    What does this script offer better than the infinitely more mature rsync? Rsync works for any combination of local and remote sources and backups as well.

  4. Siva Durga Prasad Yelugubanti says:

    what is the advantage over then rsync?

  5. Jabir Ahmed says:

    why not simply rsync?

    https://linux.die.net/man/1/rsync

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.