29 lines
1.2 KiB
Bash
29 lines
1.2 KiB
Bash
# This script creates a tar.gz backup of the /opt/AdGuardHome directory, cron jobs, and system logs.
|
|
# The backup is stored in the './backups/' directory.
|
|
#
|
|
# To automate backups, you can add this script to your crontab.
|
|
# For example, to run this backup on the 1st of every month, you would add the following line to your crontab:
|
|
# 0 0 1 * * /path/to/this/script.sh
|
|
# (Remember to replace '/path/to/this/script.sh' with the actual path to this script)
|
|
# You can edit your crontab with the command: crontab -e
|
|
|
|
# Get the current date in a suitable format for the filename
|
|
current_date=$(date +"%Y-%m-%d")
|
|
|
|
# Create the backup filename
|
|
backup_filename="adguardhome_backup_${current_date}.tar.gz"
|
|
|
|
# Default backup location
|
|
backup_location="./backups/"
|
|
|
|
# Create the 'adguardhome' directory if it doesn't exist
|
|
mkdir -p "$backup_location/adguardhome"
|
|
|
|
# Create the tar.gz archive
|
|
tar -czvf "$backup_location/adguardhome/$backup_filename" /opt/AdGuardHome /var/spool/cron/crontabs/* /var/log
|
|
|
|
# Print a success message
|
|
echo "Backup created successfully in $backup_location/adguardhome/$backup_filename"
|
|
|
|
# Delete backups older than 90 days
|
|
find "$backup_location/adguardhome" -mtime +90 -type f -delete |