sauvegardes/Plan Borg/bin/doinit-rsync

44 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
help()
{
echo "Usage: doinit-rsync [ -h | -help | --help | <COMPUTER> ]"
echo "Init borgmatic configuration for a rsync mirror."
}
#
help=0
if (( $# != 1)); then
help=1
else
for parameter in $@; do
if [ "$parameter" == "-h" ] || [ "$parameter" == "-help" ] || [ "$parameter" == "--help" ]; then
help=1
fi
done
fi
if (( $help )); then
help
else
COMPUTER="$1"
echo "== Create the mirroring directories."
mkdir -p /var/backups/borg/mirrors/${COMPUTER}/{mirror,cache}
chown borg.borg /var/backups/borg/mirrors/
chown -R borg.borg /var/backups/borg/mirrors/${COMPUTER}
echo "== Create the borgmatic configuration file."
cp /srv/borg/models/model-conf-rsync.yaml /etc/borgmatic.d/${COMPUTER}.yaml
echo "== Update the repository directory in borgmatic configuration file."
sed -i s/\<HOSTNAME\>/${COMPUTER}/g /etc/borgmatic.d/${COMPUTER}.yaml
echo "== Verify the bogmatic configuration file."
validate-borgmatic-config
echo "== Create the repository directory."
/srv/borg/bin/doinit ${COMPUTER}
fi