Respect gitignores
This commit is contained in:
parent
bb1e5fa826
commit
40d87a9d32
2 changed files with 34 additions and 1 deletions
|
|
@ -8,6 +8,7 @@ RUN apk --no-cache add \
|
||||||
openssh \
|
openssh \
|
||||||
bash \
|
bash \
|
||||||
coreutils \
|
coreutils \
|
||||||
|
git \
|
||||||
borgbackup=1.4.0-r0
|
borgbackup=1.4.0-r0
|
||||||
|
|
||||||
COPY src /src
|
COPY src /src
|
||||||
|
|
|
||||||
|
|
@ -30,12 +30,44 @@ fi
|
||||||
btrfs subvolume snapshot /btrfs-root /snapshot
|
btrfs subvolume snapshot /btrfs-root /snapshot
|
||||||
|
|
||||||
cd "/snapshot/btrfs-root$BACKUP_RELATIVE_PATH"
|
cd "/snapshot/btrfs-root$BACKUP_RELATIVE_PATH"
|
||||||
|
|
||||||
|
# Generate exclusions for git-untracked files if enabled
|
||||||
|
EXCLUDE_ARGS="--exclude-from /exclude.conf"
|
||||||
|
if [ "${IGNORE_GIT_UNTRACKED:-false}" = "true" ]; then
|
||||||
|
echo "Generating exclusions for git-untracked files..."
|
||||||
|
GIT_EXCLUDE_FILE=$(mktemp)
|
||||||
|
|
||||||
|
# Find all git repositories and list their untracked files
|
||||||
|
find . -name .git -type d 2>/dev/null | while read gitdir; do
|
||||||
|
repo_dir=$(dirname "$gitdir")
|
||||||
|
(
|
||||||
|
cd "$repo_dir"
|
||||||
|
# Get untracked files (respecting .gitignore)
|
||||||
|
git ls-files --others --exclude-standard 2>/dev/null | while read file; do
|
||||||
|
# Output path relative to backup root
|
||||||
|
echo "${repo_dir#./}/$file"
|
||||||
|
done
|
||||||
|
)
|
||||||
|
done > "$GIT_EXCLUDE_FILE"
|
||||||
|
|
||||||
|
excluded_count=$(wc -l < "$GIT_EXCLUDE_FILE")
|
||||||
|
echo "Found $excluded_count git-untracked files to exclude"
|
||||||
|
|
||||||
|
EXCLUDE_ARGS="$EXCLUDE_ARGS --exclude-from $GIT_EXCLUDE_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
borg create --stats \
|
borg create --stats \
|
||||||
--list \
|
--list \
|
||||||
--filter=AMCE \
|
--filter=AMCE \
|
||||||
--files-cache=ctime,size,inode \
|
--files-cache=ctime,size,inode \
|
||||||
--compression=zstd,12 \
|
--compression=zstd,12 \
|
||||||
--exclude-from /exclude.conf ::"{hostname}-{now:%Y-%m-%dT%H:%M:%S}" .
|
$EXCLUDE_ARGS ::"{hostname}-{now:%Y-%m-%dT%H:%M:%S}" .
|
||||||
|
|
||||||
|
# Clean up temporary exclude file
|
||||||
|
if [ -n "$GIT_EXCLUDE_FILE" ] && [ -f "$GIT_EXCLUDE_FILE" ]; then
|
||||||
|
rm -f "$GIT_EXCLUDE_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
cd -
|
cd -
|
||||||
|
|
||||||
borg prune --list --stats \
|
borg prune --list --stats \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue