Skip to content

Instantly share code, notes, and snippets.

@u1735067
Last active October 20, 2019 15:59
Show Gist options
  • Save u1735067/819e9c58c32d902a13d197067c1de21a to your computer and use it in GitHub Desktop.
Save u1735067/819e9c58c32d902a13d197067c1de21a to your computer and use it in GitHub Desktop.
Workaround to convert simple tar backup to borg backup, without leading path, using ratarmount (should works with archivemount too) and mergerfs
mkdir -p /chroot_tmp/{logs,mnt,archive_mnt,bins_mnt/dev,bins_mnt/lib,bins_mnt/lib64,bins_mnt/tmp/repo}
cd /chroot_tmp
wget https://github.com/borgbackup/borg/releases/download/1.1.10/borg-linux64 -O /bins_mnt/tmp/borg
chmod +x /chroot_tmp/bins_mnt/tmp/borg
wget https://www.busybox.net/downloads/binaries/1.31.0-defconfig-multiarch-musl/busybox-x86_64 -O /bins_mnt/tmp/busybox
chmod +x /chroot_tmp/bins_mnt/tmp/busybox
wget https://github.com/mxmlnkn/ratarmount/raw/master/ratarmount.py -O ratarmount.py
wget https://github.com/fusepy/fusepy/raw/master/fuse.py -o fuse.py
bins_mnt/tmp/borg init --verbose --progress --encryption=repokey-blake2 /chroot_tmp/bins_mnt/tmp/repo
# Copy host libs to chroot, required
cp -r /lib/x86_64-linux-gnu/ bins_mnt/lib/
cp -r /lib64/ bins_mnt/
cat <<EOF > bins_mnt/tmp/exclude
R /
- /dev
- /lib
- /lib64
- /lost+found
- /root/.ash_history
- /root/.cache
- /root/.config/borg
- /tmp
EOF
#epoch=$(date +@%s -d "$(basename "$i" | sed -re "s/.* ([0-9-]+)_([0-9]+)'([0-9]+)'([0-9]+)\..*/\1 \2:\3:\4/")")
#utcdate=$(date -u +%Y-%m-%dT%H:%M:%S -d @$(stat -c %Y "$i"))
#date=$(date +"%Y-%m-%d_%H:%M:%S" -d $epoch)
#gunzip -k my_tar.tgz
python3 ratarmount.py -c my_tar.tar archive_mnt/
mount.mergerfs archive_mnt/:bins_mnt/ mnt
mount --bind /dev mnt/dev
echo "backup"
chroot mnt/ /tmp/borg create --show-version --show-rc --verbose --list --stats --one-file-system --exclude-nodump --exclude-caches --keep-exclude-tags --patterns-from /tmp/exclude "/tmp/repo/::archive_name" 2>&1 | tee "logs/archive_name.log"
echo "backup dump"
zcat archive_mnt/dump.gz | bins_mnt/tmp/borg create --show-version --show-rc --verbose --list --stats --stdin-name dump "bins_mnt/tmp/repo/::archive_name_dump" - 2>&1 | tee "logs/archive_name_dump.log"
echo "unmount"
umount mnt/dev
umount mnt
umount archive_mnt/
#rm -f my_tar.tar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment