I feel like this is quite delicate,
I have various folders whith projects I would like to backup into a zip/tar file, but would like to avoid backing up files such as pyc files and temporary files.
I also have a Postgres db I need to backup.
Any tips for running this operation as a python script?
Also, would there be anyway to stop the process from hogging resources in the process?
Help would be very much appreciated.
If you’re on Linux (or any other form of Unix, such as MacOSX), a simple way to reduce a process’s priority — and therefore, indirectly, its consumption of CPU if other processes want some — is the nice command. In Python (same OSs), os.nice lets your program “make itself nicer” (reduce priority &c).
For backing up a PostgreSQL DB, I recommend PostgreSQL’s own tools; for zipping up a folder except the pyc files (and temporary files — however it is you identify those), Python is quite suitable. For example:
this zips all files in said subtree except those ending in
.pyc(without compression — if you want compression, add a third argumentzipfile.ZIP_DEFLATEDto thezipfile.ZipFilecall). Could hardly be easier.