Python 5 lines of code say goodbye to the pain era of backup

Applications come from needs

I'm a photo freak, even more so since I bought a DSLR! My hard drive is of course not enough, so every backup is a pain! So I thought of a program that can help to do this automatically. I happened to be learning Python, so I used python to call robocopy and wrote a small tool for automatic backup for myself. From then on, I said goodbye to the painful backup era! 5 lines of code are done, and the copy speed of robocopy is higher than the copy and paste that comes with windows, which greatly saves the backup time;

code above

#导入os 模块
import os
#获取源目录
source=raw_input("pls input source documnet:")
#获取目标目录
des=raw_input ("pls input destination document:")
#定义复制命令,robocopy 的命令参数详解, /s 复制子目录,但不复制空的子目录; /copyall 复制所有文件信息;/MON:n:监视源;发现多于 n 个更改时再次运行;/MOT:m:监视源;如果更改,在 m 分钟时间内再次运行。
cop=("robocopy %s %s /s /copyall /mot:1 /mon:2 ")%(source,des)
#执行robocopy 命令
robo=os.system(cop)

The specific use effect is shown in the following figure:

I packaged the written python into an .exe file through a packaging tool, so that it can be used on any platform in the future.
Python 5 lines of code say goodbye to the pain era of backup

After the first copy is completed, the program will not automatically exit, and will always monitor the source folder. If there are two file changes, or there is a change within 1 minute, the changed part will be copied over.
Python 5 lines of code say goodbye to the pain era of backup

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325263217&siteId=291194637