Hands-on Lab·Python Automation for IT
Python Archives and Bulk File Operations
Copying a tree, moving files, making a backup archive and unpacking somebody else's - all of it is `shutil` and two archive modules, and none of it needs a subprocess. This guide also contains the most convincing demonstration of module shadowing in the whole path, because it happened to this capture: a script named `copy.py` broke `shutil.make_archive`.
Files and Data Formats Guide 16 of 39 Intermediate
- Python3.14.4
- Control nodeUbuntu 26.04 LTS
- Managed hostsRHEL 10.0
- requests2.34.2
- paramiko5.0.0
- pytest9.1.1
- PyYAML6.0.3
- boto3 / botocore1.43.78
- TimeAbout 18 min
- Reviewed24 August 2026
Written against the versions above. `tarfile` extraction **filters** arrived in Python 3.12 and `filter="data"` becomes the default in 3.14 - which is why this guide passes it explicitly rather than relying on the version. `zstdtar` in the format list is new in 3.14.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| RUNNER01 | 192.168.0.27 | Ubuntu 26.04 LTS | Control node - every script in this path runs here | 2 Core | 4 GB | 50 GB |
Before you start
-
A tree to work on
-
Copy one file, with or without its metadata
-
Copy a whole tree
-
Move, and rename
-
rmtree, and the guard it deserves
-
An archive of a directory, in one call
-
tarfile and zipfile, when you need control
-
Extracting somebody else's archive safely
-
Disk space and finding a binary
-
The accident this capture had, kept on purpose