How do you backup your .py files while ignoring any files in .venv\ subdirectories?

I wasn’t sure where to put this but making backups is an important part of development.

I’m using Python 3.11 on Windows 10.

Backing up files that we work on is important, we don’t want to lose all our work. But it has become tricky to back up files without explicitly tracking and specifying every new project directory that I have under my master program directory called “PythonPrograms”.

I’m using the command line version of 7zip v24.01 (x64) on Windows 10. I prefer to use it in a .bat file.

I want to use 7zip to backup python programs. I have 50+ program directories where I want to backup just my .py and .md and .bat files. We add more directories every month. But every program directory also has a .venv\ subdirectory with lots of .py files I do not want to backup as they are from libraries I can reinstall later if I need to restore my program from a backup and the zip file might eventually become too large for a 32GB flash drive (the only one I have right now).

I don’t want to use a list of files in backup.lst as I don’t want to forget to add new project directories there.

How do I backup all .py files and ignore all files in all .venv\ directories? Which utility do you use?

I’d like to back up my programs with their directories on a flash drive but I will probably have to back them up to a local drive then copy the .zip file to the flash drive.

Thank you.

Use Git instead of 7z. Then add .venv to .gitignore (along with .env and a whole host of other common trash you typically don’t want to track the changes of). You can still backup a remote Git repo.

2 Likes

As James said use source control like git.

Not only do you have backups but each time you make a change you can commit the change with a log message describing why you made the change.

Now you have the history of your development and can go back and see where a feature or bug was added with its log message.