Linux
Backup Script Generator
Source, destination, compression, and retention - a complete, runnable backup script for Bash or PowerShell.
#!/bin/bash # Backup script generated by ArchSetu # Backs up "/path/to/source" to "/path/to/backups", keeping the last 7 backups. set -euo pipefail SOURCE="/path/to/source" DEST="/path/to/backups" RETENTION=7 TIMESTAMP=$(date +%Y%m%d_%H%M%S) BACKUP_NAME="backup_$TIMESTAMP.tar.gz" # Make sure the destination directory exists mkdir -p "$DEST" # Create the compressed archive tar -czf "$DEST/$BACKUP_NAME" "$SOURCE" echo "Created $DEST/$BACKUP_NAME" # Delete old backups beyond the retention count cd "$DEST" ls -1t backup_*.tar.gz 2>/dev/null | tail -n +$((RETENTION + 1)) | xargs -r rm -- echo "Backup complete - keeping the 7 most recent backups."
To automate with cron
Save the script to /path/to/backup.sh, make it executable (chmod +x), then add this line via crontab -e:
0 2 * * * /path/to/backup.sh
This is one question. ArchSetu answers it for a whole repository.
Call graph, dead code, blast radius and a health score, in about a minute.
Related tools
All Linux tools →Cron ↔ Natural Language ConverterCron syntax to plain English, and back.chmod File Permission CalculatorPick read/write/execute per owner/group/other - the numeric and symbolic chmod value.Cron to systemd Timer ConverterPaste a cron expression - the equivalent systemd OnCalendar= line for a .timer unit.Bash Strict Mode Header GeneratorPick set -e, set -u, pipefail, safe IFS, and an error trap - a commented script header.Environment Variable Naming CheckerCheck a name against portable POSIX conventions - UPPER_SNAKE_CASE, no hyphens, no leading digit.Cron Job BuilderVisual picker for the exact crontab line, plus how to install it.
Was this tool helpful?