0

I have two partition, one for use and one for backup. So, is there any tool for syncing the folder from first partition to second. Also, the tool should sync immediately whenever a change is made to file or folder. If immediate sync is not possible how do i automate my task, to sync properly Suppose i have folder mounted /dev/sda6 (windows) to window folder and running linux. I want to backup/sync /root/* to /media/window/backup and whenever i add or delete a file or folder in /root/* ,/media/window/backup should be updated.

5
  • 2
    To better understand your question: synchronized storage volumes don't actually provide backup, because a single (careless or malicious) action can remove data from both of them. Data duplication is used to protect it from failures (e.g. RAID), but there is usually only one copy presented to the user (and not two, independent partitions). What exactly is your use case? If it's backup, syncing is probably not what you should look for. – fra-san Jul 1 '20 at 8:51
  • I m backup up sorry not syncing. Also, one is ntfs (window ) partition and other is ext4, @fra-san – Machine Yadav Jul 1 '20 at 8:52
  • 2
    ".. whenever I add or delete a file ... backup should be updated": how do you plan to recover files that are deleted or changed by mistake if the copy is deleted or changed too? (This is why I brought up the distinction between synchronizaton and backup). To have a real backup you need to keep at least one copy of an older version of the same file, including deleted files. – fra-san Jul 1 '20 at 11:35
  • oh yes, hmm you are right – Machine Yadav Jul 1 '20 at 11:39
  • sorry for the question , i m foolish, i will just backup once a month, thanks for advice – Machine Yadav Jul 1 '20 at 11:39
1

Please check this:

  1. https://linuxhint.com/inotofy-rsync-bash-live-backups/
  2. https://www.b247.eu.org/2019/09/restic-incron-inotify-continuous-backup-folder-change.html

and this topic: https://serverfault.com/questions/7969/is-there-a-working-linux-backup-solution-that-uses-inotify

Or you can run rsync using cron.

1
  • Ok i will check out, hmm i will try to develop a crontab or use intofiy or something else, hmm good – Machine Yadav Jul 1 '20 at 11:41
0

Ok, so after all i got a plan. I want backup/sync but if i delete i m gone. So, pseudocode looks something like this

while inotify create/modify #executes command if create/modify 
do
   if `du source` is greater than `du destination` then #size of source is gt than dest
      rsync source/ dest -av
done

Finally did it

#!/bin/bash
if [[ `pgrep -f $0` != "$$" ]]; then
    echo "Exiting"
    exit
fi
while inotifywait -r -e modify,create /root/MachineYadav 1>/dev/null 2>/dev/null
do
    echo "0" > /tmp/KaliLinuxBackup
    clear && sleep 1.5 && echo "Backing up" && sleep 0.5
    if [[ `du -s /root/MachineYadav/ | awk '{print $1}'` -gt `du -s /root/Mount/Window/Kali-Mirror | awk '{print $1}'` ]]; then
        echo "1" > /tmp/KaliLinuxBackup
        rsync /root/MachineYadav/ /root/Mount/Window/Kali-Mirror/ -av 
    fi
    clear && echo "Finishing" && sleep 0.5
done

I will have similar implementation along with some modification. Thanks @Artem S. Tashkinov and @fra-san

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.