To run it, the Python interpreter is not needed. The command in Figure 1 converts your code into an exe file. In order to convert this, let us take the help of pyinstaller. If you don’t want to bother running the code using the interpreter, make a Windows exe file and this will work as a command. The above code is very simple and will work in INFO mode. Let us look at the code of logger1.py: import loggingįormatter = logging.Formatter(‘%(asctime)s - %(levelname)s - %(message)s’) Total_time: Runs the code for Total_time minutes. The following piece of code uses loop to run the code again and again: i = 0įrom: Specifies what the source means and takes the backup of the testing1 folder.įreq: Takes the backup after a specified minute. #modification_time = int(os.path.getmtime(file_path)) The function takes the source location and makes a dictionary of all the files present: def OriginalFiles():įor root, dir, files in os.walk(drive, topdown=True): The following function creates a dictionary, which contains the file names with the hash of the files. py(file,path_to_copy) Figure 3: CMD default path Figure 4: Sync command The following function just copies one file to the destination location: def CopyFiles(file, path_to_copy): The following function copies the whole directory with intermediaries: def CopyDir(from1, to): def md5(fname,size=4096):įor chunk in iter(lambda: f.read(size), b””): If you modify a file, then the name remains the same but the hash gets changed. The following function md5 is used to calculate the hash of the file. Repeat = int(Total_time/Freq) Figure 1: Making an exe file using pyinstaller Figure 2: Place the exe file in the Windows folder Total_time = int(All_Config.get(“total_time”))*60 Shown below are some of the variables obtained from the Sync.ini file: All_Config = ConfRead() The following code reads the Sync1.ini file: def ConfRead(): Import configparser.įrom the distutils.dir_util import copy_tree.įrom the collections, import OrderedDict. Let us now understand the code of sync.py and look at how it works.ġ. Sync.log is a file created by the sync.py. Logger1.py: The module for logger support The python program to help Backup Files Automatically contains the following three files: It is for Windows and is compatible with Python 2 and Python 3. So, to overcome this problem, I am going to demonstrate a Python script that I’ve created, which will keep taking backups of your file or folder after a specified period of time (specified by you). But it is very difficult to back up after every one hour or after every minute. But accidentally, your computer hard disk crashes. Consider that you have made an important presentation after spending a lot of time on it. Sometimes we accidentally or mistakenly delete documents. We often create new documents, files and folders in our computers. The author has created a Python program to help Backup Files Automatically. To avoid the drudgery of physically doing so every now and then, it is best to automate the process. ![]() ![]() To ensure file and folder security, prudence dictates you take a backup. Lost or deleted files are a common phenomenon.
0 Comments
Leave a Reply. |