Check two remote folders are equal with checksum | The Dev Tool | Toolel.com

This is made with Python Fabric but can easily be modified to be used for other systems. How it works:

  1. Run bash script to make checksum.txt of a folder on host_1
  2. Do the same for host_2
  3. Get these files and check them.

What is this useful for?

  1. To check that an backup server works as they're suppose to
  2. Check that two servers are up to date
  3. Check that harddrives/harddiscs/storage are not corrupted

Python Fabric Code

from fabric import Connection, task

HOST_0 = "user@321.123.321.123"
FOLDER_0 "/home/user0/folder_to_check"
HOST_1 = "user@123.321.123.321"
FOLDER_1 "/home/user1/folder_to_check"

def get_checksum(c, folder, dst):
    c.run("rm checksum.txt || true")
    c.run("cd " + folder + "&& find . -maxdepth 100 -type f -exec md5sum {} \; >> $HOME/checksum.txt") # noqa    c.get("checksum.txt", dst)


@task
def checksum(c):
    get_checksum(
        Connection(HOST_0),
        FOLDER_0,
        "/tmp/checksum-0.txt",
    )   

    get_checksum(
        Connection(HOST_1),
        FOLDER_1,
        "/tmp/checksum-1.txt",
    )

    c.run("diff /tmp/checksum-0.txt /tmp/checksum-1.txt")

You can easily replace md5sum with sha1sum for less collisions, but in most practice this is not needed.

Created by: martin

Comments

This page is only partially working without JavaScript. It will show content, but the tools and interactivity cannot be shown without JavaScript enabled. Please enable JavaScript for this page. About Us