#!/bin/sh # Format the current date NOW=$(date +"%Y-%m-%d") # Create the archive directory if it does not exist mkdir -p /backup/archive # Run rsync with an exclude file and a backup directory for changed/deleted files rsync -av --delete \ --exclude-from=/config/exclude.txt \ --backup --backup-dir=/backup/archive/$NOW \ /data/ /backup/latest/ # Find and delete archive directories older than 7 days find /backup/archive/ -mindepth 1 -maxdepth 1 -type d -mtime +7 -exec rm -rf {} +