2024-01-21 16:22:51 +00:00
|
|
|
#!/usr/bin/env bash
|
2024-01-27 18:57:31 +00:00
|
|
|
while getopts d:u:s:r:n:p: flag
|
2024-01-21 16:22:51 +00:00
|
|
|
do
|
|
|
|
case "${flag}" in
|
|
|
|
d) bkp_dir=${OPTARG};;
|
|
|
|
u) user=${OPTARG};;
|
|
|
|
s) server=${OPTARG};;
|
|
|
|
r) repository=${OPTARG};;
|
|
|
|
n) backupname=${OPTARG};;
|
2024-01-27 18:57:31 +00:00
|
|
|
p) port=${OPTARG};;
|
2024-01-21 16:22:51 +00:00
|
|
|
esac
|
|
|
|
done
|
2024-01-27 18:57:31 +00:00
|
|
|
BORG_RSH='ssh -p ${port}'
|
2024-01-21 16:22:51 +00:00
|
|
|
echo "Copy ssh priv key"
|
|
|
|
mkdir $HOME/.ssh
|
|
|
|
mkdir /logs
|
|
|
|
cp /ssh_privKey $HOME/.ssh/id_rsa
|
|
|
|
chown $(id -u):$(id -g) $HOME/.ssh/id_rsa
|
|
|
|
ssh-keyscan -t rsa $SERVER >> ~/.ssh/known_hosts
|
|
|
|
echo "Borg starting"
|
|
|
|
echo $(date +%s) > /logs/starttime
|
|
|
|
borg create -C lzma ${user}@${server}:${bkp_dir}${repository}::${backupname}_$(date -I'minutes') /backup
|
|
|
|
exitCode=$?
|
|
|
|
echo $(date +%s) > /logs/endtime
|