-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
153 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
# Hetzner StorageBox'es (one or space separated list), syntax: user@hostname | ||
export boxes="[email protected] [email protected]" | ||
export box_main="[email protected]" | ||
export boxes_to_sync="[email protected]" | ||
# Hetzner StorageBox'es (one or space separated list), syntax: user@host:port | ||
export repo_main="[email protected]:23" | ||
export repo_sync="[email protected]:23" | ||
|
||
# Folder path where repository stored on remote storage | ||
export repository_remote_folder="/home/kopia/json" | ||
export repository_folder="/home/kopia/json" | ||
|
||
# Default password what mandatory for repositories encruption | ||
export KOPIA_PASSWORD="1" | ||
# Default password what mandatory for repositories encryption | ||
export KOPIA_PASSWORD="pass" | ||
|
||
#export ui-username="k" | ||
#export ui-password="k" | ||
# Web UI | ||
export ui_username="k" | ||
export ui_password="k" | ||
|
||
# Other Kopia settings | ||
export KOPIA_CHECK_FOR_UPDATES=false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,18 +9,16 @@ | |
# Require: running from "root" or "sudo" | ||
# Note: operation will be skipped if already done before | ||
|
||
script_dir="$( cd "$( dirname "$0" )" && pwd )" | ||
source $script_dir/config | ||
|
||
set -e | ||
set -uo pipefail | ||
# set -x | ||
|
||
source config | ||
script_dir="$( cd "$( dirname "$0" )" && pwd )" | ||
source $script_dir/config | ||
# `config` overwrites: | ||
# Hetzner StorageBox'es (one or space separated list), syntax: user@hostname | ||
# Hetzner StorageBox'es (one or space separated list), syntax: user@host | ||
# Uncomment to overwrite StorageBox'es list from 'config' file | ||
# boxes="[email protected] [email protected]" | ||
# repositories="[email protected] [email protected]" | ||
|
||
# initialization | ||
cd $script_dir || { echo "Error: keys directory inaccessible" && exit 1; } | ||
|
@@ -34,25 +32,29 @@ knownhosts="$script_dir/keys/known_hosts" | |
if [[ ! -f $(which kopia) ]]; then | ||
curl -s https://kopia.io/signing-key | sudo gpg --dearmor -o /usr/share/keyrings/kopia-keyring.gpg | ||
echo "deb [signed-by=/usr/share/keyrings/kopia-keyring.gpg] http://packages.kopia.io/apt/ stable main" | sudo tee /etc/apt/sources.list.d/kopia.list | ||
apt update && apt install kopia #kopia-ui | ||
apt update && apt install kopia lftp -y #kopia-ui | ||
{ [[ -f $(which kopia) ]] && echo "Kopia installed to $(which kopia)"; } || { echo "Error: Kopia no installed, check errors" && exit 1; } | ||
fi | ||
|
||
# generate SFTP (SSH) key for access to StorageBox'es | ||
[[ -f "$script_dir"/keys/id_kopia ]] || \ | ||
ssh-keygen -o -a 100 -t ed25519 -f keys/id_kopia -C "demo key (password-less) for access to Hetzner StorageBox for Kopia" -q -N "" | ||
ssh-keygen -o -a 100 -t ed25519 -f keys/id_kopia -C "demo key (password-less) for access to SFTP storage for Kopia" -q -N "" | ||
key=$(cat keys/id_kopia.pub) | ||
|
||
# import newly created SSH key to StorageBox'es, add hosts to known_hosts | ||
for box in $boxes; do | ||
authorized_keys="$script_dir"/keys/"$box"_authorized_keys | ||
box_hostname=$(echo $box | sed 's/.*@//') | ||
[[ -n $(grep "$box" "$script_dir/keys/known_hosts") ]] || ssh-keyscan -p 23 $box_hostname >> "$knownhosts" 2> /dev/null | ||
scp -q -P 23 "$box":/home/.ssh/authorized_keys "$authorized_keys" | ||
[[ -n $(grep "$key" keys/"$box"_authorized_keys) ]] && { echo "$box : key already imported" && continue; } | ||
repositories="${repo_main} ${repo_sync}" | ||
|
||
for repo in $repositories; do | ||
username=${repo%%@*} | ||
host=$(echo $repo | sed 's/.*@//' | sed 's/:/\t/g' | awk '{print $1}') | ||
port=$(echo $repo | sed 's/.*://') | ||
authorized_keys="$script_dir"/keys/"$username@$host"_authorized_keys | ||
[[ -n $(grep "$host" "$script_dir/keys/known_hosts") ]] || ssh-keyscan -p $port $host >> "$knownhosts" 2> /dev/null | ||
scp -q -P $port "$username@$host":/home/.ssh/authorized_keys "$authorized_keys" | ||
[[ -n $(grep "$key" keys/"$username@$host"_authorized_keys) ]] && { echo "$repo : key already imported" && continue; } | ||
echo $(cat keys/id_kopia.pub) | tee -a "$authorized_keys" | ||
echo -e "echo mkdir .ssh \n chmod 700 .ssh \n put "$authorized_keys" .ssh/authorized_keys \n chmod 600 .ssh/authorized_keys" | sftp -q -P 23 "$box" > /dev/null 2>&1 | ||
echo "$box : new key imported" | ||
echo -e "echo mkdir .ssh \n chmod 700 .ssh \n put "$authorized_keys" .ssh/authorized_keys \n chmod 600 .ssh/authorized_keys" | sftp -q -P $port "$username@$host" > /dev/null 2>&1 | ||
echo "$repo : key imported" | ||
done | ||
|
||
# add scripts path to evironment | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,23 +9,48 @@ set -uo pipefail | |
script_dir="$( cd "$( dirname "$0" )" && pwd )" | ||
source $script_dir/config | ||
# `config` overwrites: | ||
# boxes_to_sync="[email protected] [email protected]" | ||
# repository_remote_folder="/home/kopia/json" | ||
# repo_sync="[email protected]:23 [email protected]:23" | ||
# repository_folder="/home/kopia/json" | ||
|
||
keyfile="$script_dir/keys/id_kopia" | ||
knownhosts="$script_dir/keys/known_hosts" | ||
|
||
for box in $boxes_to_sync; do | ||
[[ -n $(grep "$box" "$script_dir/keys/known_hosts") ]] || ssh-keyscan -p 23 $(echo $box | sed 's/.*@//') >> "$knownhosts" 2> /dev/null | ||
|
||
repo_main=$(echo $repo_main | sed 's/@/\t/g' | sed 's/:/\t/g' | awk '{print $1"@"$2}') | ||
kopia repository connect from-config --file "$script_dir/repositories/repo-$repo_main.config" | ||
|
||
for repo in $repo_sync; do | ||
|
||
username=${repo%%@*} | ||
host=$(echo $repo | sed 's/.*@//' | sed 's/:/\t/g' | awk '{print $1}') | ||
port=$(echo $repo | sed 's/.*://') | ||
|
||
[[ -n $(grep "$host" "$script_dir/keys/known_hosts") ]] || ssh-keyscan -p $port $host >> "$knownhosts" 2> /dev/null | ||
|
||
# temporary workaround Kopia bug of `kopia repository sync-to sftp` | ||
# kopia repository create sftp \ | ||
# --config-file "$script_dir/repositories/repo-$username@$host.config" \ | ||
# --cache-directory "$script_dir/cache/" \ | ||
# --username $username \ | ||
# --host $host \ | ||
# --port $port \ | ||
# --keyfile $keyfile \ | ||
# --known-hosts $knownhosts \ | ||
# --path $repository_folder | ||
# #echo -e "rm -r $repository_folder" | | ||
# eval `ssh-agent -s` | ||
# ssh-add $keyfile | ||
# lftp -e "rm -r $repository_folder" -p $port "$username@$host" #> /dev/null 2>&1 | ||
|
||
kopia repository sync-to sftp \ | ||
--config-file "$script_dir/repositories/repo-$box.config" \ | ||
--host $(echo $box | sed 's/.*@//') \ | ||
--username ${box%%@*} \ | ||
--username $username \ | ||
--host $host \ | ||
--port $port \ | ||
--keyfile $keyfile \ | ||
--known-hosts $knownhosts \ | ||
--port 23 \ | ||
--path $repository_remote_folder | ||
--path $repository_folder \ | ||
--delete | ||
# --config-file "$script_dir/repositories/repo-$username@$host.config" | ||
|
||
# kopia repository validate-provider | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,22 +2,27 @@ | |
|
||
set -e | ||
set -uo pipefail | ||
set -x | ||
# set -x | ||
|
||
script_dir="$( cd "$( dirname "$0" )" && pwd )" | ||
source $script_dir/config | ||
# `config` overwrites: | ||
# boxes_to_sync="[email protected] [email protected]" | ||
# box_main="[email protected]" | ||
# repo_sync="[email protected]:23 [email protected]:23" | ||
# repo_main="[email protected]:23" | ||
|
||
keyfile="$script_dir/keys/id_kopia" | ||
knownhosts="$script_dir/keys/known_hosts" | ||
|
||
kopia repository connect from-config --file "$script_dir/repositories/repo-$box_main.config" | ||
kopia repository connect from-config --file "$script_dir/repositories/repo-$repo_main.config" | ||
|
||
for box in $boxes_to_sync; do | ||
[[ -n $(grep "$box" "$script_dir/keys/known_hosts") ]] || ssh-keyscan -p 23 $(echo $box | sed 's/.*@//') >> "$knownhosts" > /dev/null | ||
for repo in $repo_sync; do | ||
|
||
host=$(echo $repo | sed 's/.*@//' | sed 's/:/\t/g' | awk '{print $1}') | ||
port=$(echo $repo | sed 's/.*://') | ||
|
||
[[ -n $(grep "$host" "$script_dir/keys/known_hosts") ]] || ssh-keyscan -p $port $host >> "$knownhosts" 2> /dev/null | ||
|
||
kopia repository sync-to from-config --delete --file "$script_dir/repositories/repo-$username@$host.config" | ||
|
||
kopia repository sync-to from-config --delete --file "$script_dir/repositories/repo-$box.config" | ||
done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
-----BEGIN OPENSSH PRIVATE KEY----- | ||
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW | ||
QyNTUxOQAAACC6ojXLtcCyldcFGVajNyyI1BwQsxIiisbq+H5k6o6ykgAAAMgi9SVNIvUl | ||
TQAAAAtzc2gtZWQyNTUxOQAAACC6ojXLtcCyldcFGVajNyyI1BwQsxIiisbq+H5k6o6ykg | ||
AAAEB/9J1hoyOyEyinV3nFKhAq/GvBYTrsHd8kcBRIxk2eObqiNcu1wLKV1wUZVqM3LIjU | ||
HBCzEiKKxur4fmTqjrKSAAAAQ2RlbW8ga2V5IChwYXNzd29yZC1sZXNzKSBmb3IgYWNjZX | ||
QyNTUxOQAAACAjzKGHVmYfAAQE0oti6i28WEbce8PLRptqVx7FcQEKNwAAAMhasaJAWrGi | ||
QAAAAAtzc2gtZWQyNTUxOQAAACAjzKGHVmYfAAQE0oti6i28WEbce8PLRptqVx7FcQEKNw | ||
AAAEAarmNfO8I+vGxENvS5MP9Vi97Q9w4imOS41y1d094v0CPMoYdWZh8ABATSi2LqLbxY | ||
Rtx7w8tGm2pXHsVxAQo3AAAAQ2RlbW8ga2V5IChwYXNzd29yZC1sZXNzKSBmb3IgYWNjZX | ||
NzIHRvIEhldHpuZXIgU3RvcmFnZUJveCBmb3IgS29waWEBAg== | ||
-----END OPENSSH PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILqiNcu1wLKV1wUZVqM3LIjUHBCzEiKKxur4fmTqjrKS demo key (password-less) for access to Hetzner StorageBox for Kopia | ||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICPMoYdWZh8ABATSi2LqLbxYRtx7w8tGm2pXHsVxAQo3 demo key (password-less) for access to Hetzner StorageBox for Kopia |
Oops, something went wrong.