Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/johnowhitaker/backup_script
Building a quick script for periodic backups of a folder
https://github.com/johnowhitaker/backup_script
Last synced: about 2 months ago
JSON representation
Building a quick script for periodic backups of a folder
- Host: GitHub
- URL: https://github.com/johnowhitaker/backup_script
- Owner: johnowhitaker
- License: mit
- Created: 2024-11-15T17:48:03.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2024-11-15T18:29:41.000Z (about 2 months ago)
- Last Synced: 2024-11-15T19:19:12.648Z (about 2 months ago)
- Language: Python
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
NB, this is superseded by https://johnowhitaker.github.io/autobackup/ (https://github.com/johnowhitaker/autobackup) - ignore other than for reference
# backup_script
Building a quick script for periodic backups of a folder
## Usage
1. Create a `backup_config.json` file in the root of the project with the following structure:
```
{
"source_directory": "/path/to/source",
"destination_directory": "/path/to/backups",
"max_ages": [2, 14, 60]
}
```2. Create a service file (e.g. `/etc/systemd/system/backup.service`):
```
[Unit]
Description=Hourly Backup Service[Service]
ExecStart=/path/to/your/backup_script.py[Install]
WantedBy=multi-user.target
```3. Create a timer file (e.g. `/etc/systemd/system/backup.timer`):
```
[Unit]
Description=Run Backup Service Hourly[Timer]
OnCalendar=hourly[Install]
WantedBy=timers.target
```4. Enable and start the timer:
```
sudo systemctl enable backup.timer
sudo systemctl start backup.timer
```Make sure you have execute permissions for the script:
```
chmod +x backup_script.py
```## Testing
I made a little test script (`test.py`) to test the backup script as a final sanity check. Make sure you set source and destination directories in the `backup_config.json` file.
To run it:
```
mkdir -p ~/backup_script/demo_src
mkdir -p ~/backup_script/demo_dst
python test.py
```And check the `backup.log` file to see the output, plus the `demo_dst` folder to see the backup directories.