-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathTimeMachinePruning.sh
46 lines (31 loc) · 1.19 KB
/
TimeMachinePruning.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
####################################
#### Start user-defined variables ####
# Define the Time Machine Backup location
backupLocation="/PATH/TO/TIMEMACHINEBACKUPS/FOLDERABOVEDATENAMEDFOLDERS"
# Define how many days back you want to keep
thresholdDays=60
#### End user-defined variables ####
####################################
# Get threshold date in timestamp form
thresholdTimestamp=$(/bin/date -j -v -"$thresholdDays"d "+%s")
# Change directories to Time Machine Backups
/usr/bin/cd "$backupLocation"
# Loop through the Time Machine Backup folders
for f in *; do
# Ignore "Latest"
if [ "$f" != "Latest" ]; then
# Get just the date part of the name
testDate=${f:0:10}
# Get the timestamp of the date
testTimestamp=$(/bin/date -j -u -f "%Y-%m-%d" "$testDate" "+%s")
# Compare it to the threshold timestamp
if [ "$thresholdTimestamp" -gt "$testTimestamp" ]; then
/bin/echo "Going to delete $backupLocation/$f"
/usr/bin/tmutil delete "$backupLocation/$f"
# End comparison of timestamps
fi
# End checking not Latest folder
fi
# End looping through folders
done