host info updates
[distro-setup] / mail-backup-clean
1 #!/bin/bash
2 # Copyright (C) 2016 Ian Kelling
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
17 shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4
18 set -eE -o pipefail
19 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR
20
21 ## This would delete backups that we already have in snapshots,
22 ## 1 second granularity, so we could have some duplicates. However,
23 ## this doesn't account for files received then accidentally deleted,
24 ## all in between two snapshots, so they aren't in any snapshot.
25 ## So, instead, just keep a bunch of backups based on time.
26
27 # cd /mnt/o/btrbk
28 # tmp=(o*)
29 # last_snap_date=${tmp[-1]#o.}
30 # time=$(( $(date -d $(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<$last_snap_date) +%s) -1 ))
31 # find /bu/md -type f \! -newermt @$time -delete
32
33 find /bu/md -type f -mtime +100 -delete