Skip to content

Commit

Permalink
cleanup use PREREQ and systemd examples
Browse files Browse the repository at this point in the history
  • Loading branch information
per2jensen committed Aug 9, 2024
1 parent bfae31c commit 232f988
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
51 changes: 51 additions & 0 deletions v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,57 @@ verbose:
# -va
````

# Systemctl examples
I have dar-backup scheduled to run via systemd --user settings.

The files are located in: ~/.config/systemd/user

Once the .service and .timer files are in place, timers must be enabled and started.

````
systemctl --user enable dar-inc-backup.timer
systemctl --user start dar-inc-backup.timer
systemctl --user daemon-reload
````

Verify your timers are set up as you want:

````
systemctl --user list-timers
````


## Service: dar-back --incremental-backup

File: dar-inc-backup.service
````
[Unit]
Description=dar-backup INC
StartLimitIntervalSec=120
StartLimitBurst=1
[Service]
Type=oneshot
TimeoutSec=infinity
RemainAfterExit=no
ExecStart=/bin/bash -c '. /home/user/programmer/dar-backup.py/venv/bin/activate && dar-backup --incremental-backup --verbose'
````

## Timer: dar-back --incremental-backup

File: dar-inc-backup.timer
````
[Unit]
Description=dar-backup INC timer
[Timer]
OnCalendar=*-*-04/3 19:03:00
Persistent=true
[Install]
WantedBy=timers.target
````


# list contents of an archive
```
. <the virtual evn>/bin/activate
Expand Down
19 changes: 18 additions & 1 deletion v2/dar_backup/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import logging
import os
import re
import subprocess
import sys

from datetime import datetime, timedelta
Expand Down Expand Up @@ -158,6 +159,22 @@ def main():
args.verbose and (print(f"--cleanup-specific-archive: {args.cleanup_specific_archive}"))


# run PREREQ scripts
if 'PREREQ' in config_settings.config:
for key in sorted(config_settings.config['PREREQ'].keys()):
script = config_settings.config['PREREQ'][key]
try:
result = subprocess.run(script, shell=True, check=True)
logger.info(f"PREREQ {key}: '{script}' run, return code: {result.returncode}")
logger.info(f"PREREQ stdout:\n{result.stdout}")
except subprocess.CalledProcessError as e:
logger.error(f"Error executing {key}: '{script}': {e}")
if result:
logger.error(f"PREREQ stderr:\n{result.stderr}")
print(f"Error executing {script}: {e}")
sys.exit(1)


if args.alternate_archive_dir:
config_settings.backup_dir = args.alternate_archive_dir

Expand Down Expand Up @@ -187,7 +204,7 @@ def main():
if len(error_lines) > 0:
args.verbose and print("\033[1m\033[31mErrors\033[0m encountered")
for line in error_lines:
print(line)
args.verbose and print(line)
sys.exit(1)
else:
args.verbose and print("\033[1m\033[32mSUCCESS\033[0m No errors encountered")
Expand Down
2 changes: 1 addition & 1 deletion v2/dar_backup/dar_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ def main():
if len(error_lines) > 0:
args.verbose and print("\033[1m\033[31mErrors\033[0m encountered")
for line in error_lines:
print(line)
args.verbose and print(line)
sys.exit(1)
else:
args.verbose and print("\033[1m\033[32mSUCCESS\033[0m No errors encountered")
Expand Down

0 comments on commit 232f988

Please sign in to comment.