Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python 5 lines of code bid farewell to the painful era of backup

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Application originates from demand

I am a photo maniac, especially since I bought a SLR! Of course, my hard drive is not enough, so every backup is a very painful thing! So I thought of a do-it-yourself program that could help me do this automatically. I happened to be learning Python, so I used python to call robocopy to write an automatic backup gadget for my own use. From then on, I bid farewell to the painful backup era! Five lines of code are done, and the copy speed of robocopy is faster than the copy and paste that comes with windows, which greatly saves backup time.

Code # Import os module import os# get source directory source=raw_input ("pls input source documnet:") # get target directory des=raw_input ("pls input destination document:") # define copy command, robocopy command parameters are detailed, / s copy subdirectories, but not empty subdirectories; / copyall copy all file information; / MON:n: monitor source; run again when more than n changes are found; / MOT:m: monitor source If you change, run it again in m minutes. Cop= ("robocopy% s / s / copyall / mot:1 / mon:2")% (source,des) # executes the robocopy command robo=os.system (cop) as shown in the following figure:

I package the written python into a .exe file through a packaging tool, so that I can use it on any platform in the future.

After the first copy is completed, the program will not exit automatically and will always monitor the source folder. If there are two file changes, or if there are changes within 1 minute, the changes will be copied over.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report