diff --git a/debian/debian-download-configure-wrestic.sh b/wrestic/install-wrestic-local.sh similarity index 100% rename from debian/debian-download-configure-wrestic.sh rename to wrestic/install-wrestic-local.sh diff --git a/wrestic/install-wrestic-sftp.sh b/wrestic/install-wrestic-sftp.sh new file mode 100644 index 0000000..07fd23a --- /dev/null +++ b/wrestic/install-wrestic-sftp.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +if [ "$EUID" -ne 0 ] + then + echo "Please run as root" + exit +fi + +isInFile=$(cat /home/akanealw/.ssh/config | grep -c "truenas") +if [ $isInFile -eq 0 ] + then + echo "" >> /home/akanealw/.ssh/config + echo "Host truenas" >> /home/akanealw/.ssh/config + echo "Hostname 192.168.1.41" >> /home/akanealw/.ssh/config + echo "Port 22" >> /home/akanealw/.ssh/config + echo "User akanealw" >> /home/akanealw/.ssh/config + echo "IdentityFile ~/.ssh/truenas" >> /home/akanealw/.ssh/config + chmod 600 /home/akanealw/.ssh/config +fi + +if [[ ! -f /home/akanealw/.ssh/truenas ]] + then + echo "-----BEGIN OPENSSH PRIVATE KEY-----" > /home/akanealw/.ssh/truenas + echo "b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW" >> /home/akanealw/.ssh/truenas + echo "QyNTUxOQAAACCDKl0DNjKWKlSpbCGeKjmA3tc0pKDvAiMfWQ83h0JVlQAAAJhNQ67sTUOu" >> /home/akanealw/.ssh/truenas + echo "7AAAAAtzc2gtZWQyNTUxOQAAACCDKl0DNjKWKlSpbCGeKjmA3tc0pKDvAiMfWQ83h0JVlQ" >> /home/akanealw/.ssh/truenas + echo "AAAEBoM2bsFqToHCHKO3F6MvOlObGaiNXw6UPcyBlyfbSAvYMqXQM2MpYqVKlsIZ4qOYDe" >> /home/akanealw/.ssh/truenas + echo "1zSkoO8CIx9ZDzeHQlWVAAAAEWFrYW5lYWx3QExhcHRvcFBDAQIDBA==" >> /home/akanealw/.ssh/truenas + echo "-----END OPENSSH PRIVATE KEY-----" >> /home/akanealw/.ssh/truenas + chown akanealw:akanealw /home/akanealw/.ssh/truenas + chmod 600 /home/akanealw/.ssh/truenas +fi + +if [[ ! -f /home/akanealw/.config/wrestic/wrestic.toml ]] + then + apt update + apt-get install -y restic + mkdir -pv /home/akanealw/.config/wrestic + mkdir -pv /home/akanealw/restic/restore + mkdir -pv /root/restic/restore + wget -qO /usr/local/bin/wrestic http://192.168.1.50/files/wrestic/wrestic + wget -qO /home/akanealw/.config/wrestic/wrestic.toml http://192.168.1.50/files/wrestic/wrestic.toml + wget -qO /home/akanealw/scripts/wrestic-backup-to-truenas.sh http://192.168.1.50/scripts/wrestic/wrestic-backup-to-truenas.sh + sed -i "s/changemepls/$HOSTNAME/g" /home/akanealw/.config/wrestic/wrestic.toml + sed -r 's/(resticbackups)(.*)/\1\L\2\E/g' /home/akanealw/.config/wrestic/wrestic.toml > /home/akanealw/.config/wrestic/wrestic2.toml + mv /home/akanealw/.config/wrestic/wrestic.toml /home/akanealw/.config/wrestic/wresticbackup.toml + mv /home/akanealw/.config/wrestic/wrestic2.toml /home/akanealw/.config/wrestic/wrestic.toml + rm .config/wrestic/wresticbackup.toml + chown -R akanealw:akanealw /home/akanealw/.config + chown -R akanealw:akanealw /home/akanealw/restic + chown -R akanealw:akanealw /home/akanealw/scripts + chmod +x /home/akanealw/scripts/wrestic-backup-to-truenas.sh + chmod +x /usr/local/bin/wrestic + else + echo "Wrestic is already configured." +fi diff --git a/wrestic/wrestic-remove.sh b/wrestic/remove-wrestic.sh similarity index 100% rename from wrestic/wrestic-remove.sh rename to wrestic/remove-wrestic.sh diff --git a/wrestic/wrestic-backup-to-truenas.sh b/wrestic/wrestic-backup-to-truenas-local.sh similarity index 100% rename from wrestic/wrestic-backup-to-truenas.sh rename to wrestic/wrestic-backup-to-truenas-local.sh diff --git a/wrestic/wrestic-backup-to-truenas-sftp.sh b/wrestic/wrestic-backup-to-truenas-sftp.sh new file mode 100644 index 0000000..fda6b49 --- /dev/null +++ b/wrestic/wrestic-backup-to-truenas-sftp.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if ping -c 1 192.168.1.41 > /dev/null 2>&1 + then + sudo wrestic backup + else + echo "TrueNAS is offline" +fi