From 52c786a7c83e8f1b641bb4c87444e072edaef755 Mon Sep 17 00:00:00 2001 From: Stella Nyamekye Anyebayaaka Appiok Date: Thu, 16 Jul 2026 23:04:28 +0000 Subject: [PATCH 1/4] Creating code file --- Automatic_file_backup/automatic_file_backup.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Automatic_file_backup/automatic_file_backup.py diff --git a/Automatic_file_backup/automatic_file_backup.py b/Automatic_file_backup/automatic_file_backup.py new file mode 100644 index 0000000..e69de29 From a5af9aec1bc150cefd2a715f999b10f7b1ab2c5a Mon Sep 17 00:00:00 2001 From: Stella Nyamekye Anyebayaaka Appiok Date: Thu, 16 Jul 2026 23:05:53 +0000 Subject: [PATCH 2/4] creating the readme.md file --- Automatic_file_backup/ReadMe.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Automatic_file_backup/ReadMe.md diff --git a/Automatic_file_backup/ReadMe.md b/Automatic_file_backup/ReadMe.md new file mode 100644 index 0000000..e69de29 From 35878bd8e6f97e0f63c75e6e76d8667c423421ff Mon Sep 17 00:00:00 2001 From: Stella Nyamekye Anyebayaaka Appiok Date: Thu, 16 Jul 2026 23:07:19 +0000 Subject: [PATCH 3/4] adding code to the code file --- .../automatic_file_backup.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Automatic_file_backup/automatic_file_backup.py b/Automatic_file_backup/automatic_file_backup.py index e69de29..21c8392 100644 --- a/Automatic_file_backup/automatic_file_backup.py +++ b/Automatic_file_backup/automatic_file_backup.py @@ -0,0 +1,28 @@ +import time +import schedule +import datetime +import shutil +import os + +source_dir = "" # Set this to the folder you want to back up +destination_dir = "" # Set this to where backups should be saved + + +def copy_folder_to_directionary(source, dest): + today = datetime.date.today() + dest_dir = os.path.join(dest, str(today)) + + try: + shutil.copytree(source, dest_dir) + print(f"Folder copied to: {dest_dir}") + + except FileExistsError: + print(f"folderalready exists in {dest}") + + +schedule.every().day.at("12:00").do(lambda: copy_folder_to_directionary(source_dir, destination_dir) + ) + +while True: + schedule.run_pending() + time.sleep(60) From a9712619f441022af0d991e74dce66fca6f9463b Mon Sep 17 00:00:00 2001 From: Stella Nyamekye Anyebayaaka Appiok Date: Thu, 16 Jul 2026 23:11:47 +0000 Subject: [PATCH 4/4] adding information about project into the readme file --- Automatic_file_backup/ReadMe.md | 65 +++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/Automatic_file_backup/ReadMe.md b/Automatic_file_backup/ReadMe.md index e69de29..e0e03a3 100644 --- a/Automatic_file_backup/ReadMe.md +++ b/Automatic_file_backup/ReadMe.md @@ -0,0 +1,65 @@ +# Daily Folder Backup + +A tiny Python script that automatically backs up a folder to a destination directory once a day, timestamped by date. + +## Features + +- Runs continuously in the background and triggers a backup every day at a set time +- Copies an entire folder tree using `shutil.copytree` +- Names each backup by the date it was created (e.g. `2026-07-16`), so you get one snapshot per day +- Skips silently (with a message) if a backup for that day already exists, instead of crashing + +## Requirements + +- Python 3.7+ +- [`schedule`](https://pypi.org/project/schedule/) library + +Install the dependency with: + +```bash +pip install schedule +``` + +## Configuration + +Open the script and set the two path variables at the top: + +```python +source_dir = "/path/to/folder/to/back/up" +destination_dir = "/path/to/where/backups/go" +``` + +By default, the job runs daily at `12:00` (24-hour format). To change the time, edit this line: + +```python +schedule.every().day.at("12:00").do(...) +``` + +## Usage + +Run the script and leave it running (e.g. in a terminal, `tmux`/`screen` session, or as a background service): + +```bash +python automatic_file_backup.py +``` + +Each day at the scheduled time, it will create a new folder inside `destination_dir` named after the current date, containing a full copy of `source_dir`. + +## How it works + +1. `schedule` checks every 60 seconds whether it's time to run the backup job. +2. When triggered, `copy_folder_to_directionary()` builds a destination path using today's date. +3. `shutil.copytree` recursively copies the source folder into that dated destination. +4. If a folder for that date already exists, a `FileExistsError` is caught and a message is printed instead of overwriting or crashing. + +## Limitations & ideas for contribution + +- Only one backup per day is supported (running twice in a day just logs "already exists") +- No cleanup/rotation of old backups — the destination folder will grow indefinitely +- No logging to a file, only `print` statements +- Could be extended with: + - Configurable backup retention (e.g. delete backups older than N days) + - Support for multiple source folders + - Compression (zip/tar) instead of a raw folder copy + - A config file or CLI args instead of hardcoded paths + - Proper logging via Python's `logging` module