divers/reborg.sh

66 lines
1.4 KiB
Bash
Raw Normal View History

2022-05-22 11:37:19 +02:00
#! /bin/bash
# reborg.sh
# A script for migrating borg repos
# for example from clear repo to encrypted repo
# by Djan GICQUEL
# Licence : CC SA-NC
repo1=""
repo2=""
txtfile=""
#-----------------------------------------------------------
if [ "$repo1" = "" ];then
echo "repo1 is empty";exit
fi
if [ "$repo2" = "" ];then
echo "repo2 is empty";exit
fi
if [ ! -f "$repo1/config" ]; then
2022-05-22 11:37:19 +02:00
echo "unable to find borgbackup repo config file.";sleep 3;exit
fi
if [ ! -d "$repo1/data" ]; then
2022-05-22 11:37:19 +02:00
echo "unable to find borgbackup data folder.";sleep 3;exit
fi
if [ ! -f "$repo2/config" ]; then
2022-05-22 11:37:19 +02:00
echo "unable to find borgbackup repo config file.";sleep 3;exit
fi
if [ ! -d "$repo2/data" ]; then
2022-05-22 11:37:19 +02:00
echo "unable to find borgbackup data folder.";sleep 3;exit
fi
echo "$repo1"
echo "will be imported in"
echo "$repo2"
echo ""
read -p "OK ?" CONTINUE
if [ -f $txtfile ];then
2022-05-22 11:37:19 +02:00
echo "File exist, resuming."
else
echo "$(borg list --format='{archive} {time:%Y-%m-%dT%H:%M:%S}{LF}' $repo1)" > $txtfile
echo "archive list genereted"
read -p "Continue ?" CONTINUE
fi
cat $txtfile | while read A T;do
2022-05-22 11:37:19 +02:00
echo "Importing $A..."
borg export-tar $repo1::$A - | borg import-tar --timestamp=$T $repo2::$A -
echo "Archive $A imported."
echo ""
tail -n +2 "$txtfile" > "$txtfile.tmp" && mv "$txtfile.tmp" "$txtfile"
done
echo "Deleting $txtfile"
rm $txtfile
2022-05-22 11:37:19 +02:00
echo ""
echo "End of the script."