A simple bash script to archive system logs periodically using cronjobs and passwordless sudo for tar.
- Backs up
/var/log/*.logfiles - Archives backups to
~/log-backups - Automates using a cronjob
- Uses passwordless sudo for smooth automation
- Configure passwordless sudo for
/bin/tar - Set up a cron job to run the script every minute or change to your preferred time
In the backup script, sudo /bin/tar is used instead of simply sudo tar.
This is intentional:
- Using
/bin/tarensures that the script calls the exact trusted system binary located at/bin/tar. - It avoids any security risks where another
tarbinary (possibly malicious) could be found elsewhere in the system's PATH. - This ensures the backup is performed securely and reliably.