divers/reborg.sh

66 lines
1.4 KiB
Bash
Executable File

#! /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
echo "unable to find borgbackup repo config file.";sleep 3;exit
fi
if [ ! -d "$repo1/data" ]; then
echo "unable to find borgbackup data folder.";sleep 3;exit
fi
if [ ! -f "$repo2/config" ]; then
echo "unable to find borgbackup repo config file.";sleep 3;exit
fi
if [ ! -d "$repo2/data" ]; then
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
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
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
echo ""
echo "End of the script."