Lab 3 of 5
Β·
Semi-Guided
Generate Timestamped Backup Filenames
Objective: Use datetime to build a fixed-format backup filename and a human-readable change log entry.
Instructions
Create a file called lab3.py. Use a fixed datetime so the output matches exactly β do not use datetime.now():
from datetime import datetime
ts = datetime(2025, 4, 15, 9, 30, 0)
Use ts to generate:
- A backup filename in the format:
backup_<YYYYMMDD>_<HHMMSS>.cfg - A change log entry in the format:
[2025-04-15 09:30:00] Config backup created for sw-core-01
Your output must match exactly:
backup_20250415_093000.cfg
[2025-04-15 09:30:00] Config backup created for sw-core-01
Run it with python3 lab3.py. Paste your output below and submit.
π‘ Show Hint
Use ts.strftime("%Y%m%d_%H%M%S") for the filename timestamp and ts.strftime("%Y-%m-%d %H:%M:%S") for the log entry. Build both with f-strings.
Paste Your Output