How would I go about setting up a condition depending on the number of days have gone?
If you want to check the actual number of days that have passed since the last full backup, instead of just the current day, you'll need to save the timestamp of the last full backup and check that.
Possibly simplest would be to just check the unix timestamp, i.e. number of seconds that have passed:
#!/bin/bash
file=last_full
elapsed=999999999
min_interval=$((6*86400 + 12*3600)) # 6 d + 12 h
now=$(date +%s)
if [[ -f "$file" ]]; then
elapsed=$(( now - $(< "$file") ))
fi
if (( elapsed > min_interval )); then
echo run full backup...
echo "$now" > "$file"
else
echo run incremental backup...
fi
Or convert the number of seconds into days first, with e.g. days=$(( elapsed / 86400 )) or with rounding days_rounded=$(( (elapsed + 86400/2) / 86400 )).
This way it won't matter if the script gets missed one Sunday, it'll then just run the next full backup the next time it runs, e.g. on Monday. The downside is that all the next full backups will then also shift to Mondays. Though you could bypass that by also checking the weekday, e.g.:
if (( elapsed > min_interval )) || [[ $(date +%w) = 0 ]]; then
echo run full backup...
...
fi
(The point of the 6.5 day cutoff is to avoid issues if the script's execution gets delayed slightly due to system load on one day, causing the next interval to be a few seconds short of full days.)
That same skript I would than add to /etc/cron.weekly and /etc/cron.daily
If you run it from both, it'll run twice on Sundays. (Or whatever the day cron.weekly runs is anyway.) If the script itself checks which one it needs to do, you can just run it from cron.daily.
An alternative to using cron.daily and cron.weekly would be to make two lines in crontab:
0 4 * * 0 /path/to/mybackup.sh full
0 4 * * 1-6 /path/to/mybackup.sh incremental
And then check the first command line argument $1 in the script.
This would avoid the double run on Sundays, but would have the same problem as before: missing a Sunday run would miss the full backup for the week.