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
|
|
|
|
|
2022-06-12 17:40:25 +02:00
|
|
|
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
|
|
|
|
|
2022-06-12 17:40:25 +02:00
|
|
|
if [ ! -d "$repo1/data" ]; then
|
2022-05-22 11:37:19 +02:00
|
|
|
echo "unable to find borgbackup data folder.";sleep 3;exit
|
|
|
|
fi
|
|
|
|
|
2022-06-12 17:40:25 +02:00
|
|
|
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
|
|
|
|
|
2022-06-12 17:40:25 +02:00
|
|
|
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
|
|
|
|
|
2022-06-12 17:40:25 +02:00
|
|
|
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
|
|
|
|
|
2022-06-12 17:40:25 +02:00
|
|
|
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"
|
2022-06-12 17:40:25 +02:00
|
|
|
rm $txtfile
|
2022-05-22 11:37:19 +02:00
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "End of the script."
|