commit f45f4d38ebb7c0ea34092b3ce453db91fd73a927
parent 2b2f702327a35b07b7f60807153f709f30ab6dcc
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Tue, 29 Oct 2024 11:44:11 -0700
Add support for excluding certain files
This adds a negation operator ('!') which excludes all paths beginning
with whatever follows the operator. This is useful if you want to
backup most files in a directory but want to exclude a few large,
redundant files.
One caveat of the implementation is that it treats a/b and a//b
differently.
Diffstat:
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/srvbackup b/srvbackup
@@ -1,5 +1,5 @@
#!/bin/sh
-# Copyright 2023 Jacob R. Edwards
+# Copyright 2023, 2024 Jacob R. Edwards
# srvbackup, a server backup script
#
# This script is to be put on the server and is meant to be used
@@ -35,7 +35,29 @@ update() (
IFS='
'
cd /
- pax -w -uf "$backup" $(sed '/^[ ]*#/d' < /etc/backup/list)
+
+ matchfiles | pax -w -uf "$backup"
+)
+
+matchfiles() (
+ IFS='
+'
+ sed '/^!/d; /^[ ]*#/d' < /etc/backup/list |
+ xargs -I% find % -type f -or -type d -and -empty |
+ awk 'BEGIN {
+ for (a in ARGV) {
+ argv[a] = ARGV[a]
+ delete ARGV[a]
+ }
+ }
+ {
+ for (a in argv) {
+ if (substr($0, 1, length(argv[a])) == argv[a]) {
+ next
+ }
+ }
+ print
+ }' $(sed -n '/^!/ s///p' < /etc/backup/list)
)
if test $# -eq 0; then