Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Sunday, July 26, 2020

Backup(Transferring and Synchronizing files) using python multiprocessing and rsync !

rsync(remote sync) is a utility for efficiently transferring and synchronizing files between a computer and an external storage

  1. Copy or sync files locally:

  2. rsync -zvh [Source-Files-Dir] [Destination]

  3. Copy or sync directory locally:

  4. rsync -zavh [Source-Files-Dir] [Destination]

  5. Copy files and directories recursively locally:

  6. rsync -zrvh [Source-Files-Dir] [Destination]  

  7. Sample  python code  script to do a backup using python...


  8. #!/usr/bin/env python

    import subprocess

    from multiprocessing import Pool


    from os import walk 


    src= "/home/user/data/"

    dest="/home/user/data/backup/"

    def backupData(dir):

        print("dir = "+ src+dir +" dest = " + dest+dir)

        subprocess.call(["rsync", "-arq", src+dir, dest+dir]) 


    dirList = []

    for (root, dirs, files) in walk(src):

        dirList.extend(dirs)

        break;

    print (dirList)

    p= Pool(len(dirList))

    p.map(backupData, dirList)


Read More...

Pages

 ©mytechtoday.com 2006-2010

 ©Mytechtoday

TOP