Inspiration
Backing up your data on a regular basis can sometimes be time-consuming. It's a repetitive task, and it would be stupid to use the power of the human brain to do repetitive tasks. So why not automate the process of backing up your data? This can be easily done, by just writing a few lines of code. I have used Python here, as it is very easy to automate tasks using it.
What it does
So some basics:
When we back up our files locally on our HDD or a storage device, we mostly convert them into a ZIP file. ZIP files can contain several files with their compressed contents. And, as ZIP files can also hold many folders and subfolders, it becomes a handy way to backup files by packaging them into one.
A single ZIP file, called an archive file, can be created automatically using Python functions in the zipfile module.
How we built it
So the workflow goes like this:-
- Select the folder to be backed up.
- Select the Storage device, where data needs to be backedUp, If not found, exit program by showing a message
- if storage device found, create a directory with .zip format same name as the directory on local system
- Start backing up, when done, exit, with a message on the screen
What we learned
Learned about the Zip FIle Module
What's next for File Backup Automated using Python
To implement it for a Client-Server architecture model.
The Script
Here is the script :- import zipfile, os def backup(folder) folder = os.path.abspath(folder) offset=1 while True: zip_name=os.path.basename(folder)+'_'+str(offset)+'.zip' if not os.path.exists(zip_name): break offset+=1 print("Successfully created file " %s" %(zip_name)) backupzip=zipfile.ZipFile(zip_name,'w') for foldername,subfolders,filenames in os.walk(folder): backupzip.write(foldername) backupzip.close() print("done")
Log in or sign up for Devpost to join the conversation.