Running Backup Scripts on Boot and Wake with systemd
If you’re running automated backups on a laptop, traditional schedulers like cron or fcron might not be ideal. Your machine isn’t always on, and you might want to trigger backups specifically when the system starts up or wakes from sleep. Here’s how to use systemd to run your backup script at these key moments. The systemd Service File Create /etc/systemd/system/backup.service: [Unit] Description=Run backup script at boot and wake-up After=multi-user.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target [Service] Type=oneshot User=yourusername Group=yourgroup ExecStart=/path/to/backup-script.sh [Install] WantedBy=multi-user.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target The User and Group directives ensure the script runs as your user instead of root. This is important for: ...