You are not logged in.

#1 2018-06-10 23:54:11

bashM0nk3y
Member
From: the big she-bang
Registered: 2018-05-26
Posts: 49

[SOLVED] Script for backup over network using ssh with pubkey auth

Hello all, I hope I posted this in the apporpriate sub-forum...

So I have a small script to backup the majority of my home directory over the network using rsync over ssh with pubkey authetication.

My problem is that I have to repeatedly enter my passphrase associated with the public key every time a new transfer is started with rsync.

My ideal solution would entail entering this passphrase only once but i'm not quite sure how to go about it. I've pondered on possibly using one rsync command with multiple $SRC arguments, but i'm not sure if that would even work considering there are also multiple destination paths. Am I over-thinking this? or...?

Here's the script: (sorry for the long lines, I wonder if there is a way to make the 'code' tags word-wrap?)

#!/bin/bash

# small script to backup the majority of /home/cory

# Desktop
printf "\nrsync-ing ~/Desktop\n"
/usr/bin/rsync -avzh -e "ssh -p443" /home/cory/Desktop/ cory@$LANSRV:/home/cory/thinkpad/Desktop || { echo "Script error while syncing ~/Desktop" >&2;exit 1; }

# Documents
printf "\nrsync-ing ~/Documents\n"
/usr/bin/rsync -avzh -e "ssh -p443" --exclude=**/*LinuxISOs*/ --exclude=**/*WindowsISOs*/ --exclude=**/*CEH_prep*/ /home/cory/Documents/ cory@$LANSRV:/home/cory/thinkpad/Documents || { echo "Script error while syncing ~/Documents" >&2;exit 1; }

# Pictures
echo "rsync-ing ~/Pictures"
/usr/bin/rsync -avzh -e "ssh -p443" /home/cory/Pictures/ cory@$LANSRV:/home/cory/thinkpad/Pictures || { echo "Script error while syncing ~/Pictures" >&2;exit 1; }

# Downloads
printf "\nrsync-ing ~/Downloads\n"
/usr/bin/rsync -avzh -e "ssh -p443" --exclude=**/*pluralsight_exersize_files*/ /home/cory/Downloads/ cory@$LANSRV:/home/cory/thinkpad/Downloads || { echo "Script error while syncing ~/Downloads" >&2;exit 1; }

# Scripts
printf "\nrsync-ing ~/bin\n"
/usr/bin/rsync -avzh -e "ssh -p443" /home/cory/bin/ cory@$LANSRV:/home/cory/thinkpad/bin || { echo "Script error while syncing ~/bin" >&2;exit 1; }

# Videos
printf "\nrsync-ing ~/Videos\n"
/usr/bin/rsync -avzh -e "ssh -p443" /home/cory/Videos/ cory@$LANSRV:/home/cory/thinkpad/Videos || { echo "Script error while syncing ~/Videos" >&2;exit 1; }

# Arch Build System
printf "\nrsync-ing ~/abs\n"
/usr/bin/rsync -avzh -e "ssh -p443" /home/cory/abs/ cory@$LANSRV:/home/cory/thinkpad/abs || { echo "Script error while syncing ~/abs" >&2;exit 1; }

# Home config dir
printf "\nrsync-ing ~/etc\n"
/usr/bin/rsync -avzh -e "ssh -p443" /home/cory/etc/ cory@$LANSRV:/home/cory/thinkpad/etc || { echo "Script error while syncing ~/etc" >&2;exit 1; }

# Home log files
printf "\nrsync-ing ~/logs\n"
/usr/bin/rsync -avzh -e "ssh -p443 -i /home/cory/.ssh/id_rsa" /home/cory/logs/ cory@$LANSRV:/home/cory/thinkpad/logs || { echo "Script error while syncing ~/logs" >&2;exit 1; }

printf "\nSuccess\n" && exit 0

[SOLUTION]
Added private key to ssh-agent.

Last edited by bashM0nk3y (2018-06-16 20:46:23)

Offline

#2 2018-06-11 00:07:51

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] Script for backup over network using ssh with pubkey auth

If you only ever run it when you are present, just add the key to your agent.

If it is intended for unattended backups, then create a specific key without a passphrase and restrict it to that one script.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB