david/sshbackup
david
/
sshbackup
Archived
1
0
Fork 0

fixed bug in check for listfile

This commit is contained in:
david 2013-04-27 11:58:10 +02:00
parent 07ae55dea9
commit d57b2e3ee3
3 changed files with 77 additions and 35 deletions

9
listfile_sample Normal file
View File

@ -0,0 +1,9 @@
# in here are the backup sources supposed to be
# one source per line (no tailing slashes)
# <user@remotemachine:/remote/path> </local/path> <versions>
user@server1.example.com:/srv/projects/* /home/david/testback/git 3
user@server2.example.com:/srv/backup/* /home/david/testback/duffman 3
user2@server3:/media/storage2/* /home/david/testback/cartman 30

View File

@ -1,9 +0,0 @@
# in here are the backup sources supposed to be
# one source per line (no tailing slashes, bandwidth limit in kbytes/s is optional)
# <user@remote machine> <remote path> <local path> <versions> <bandwidth limit>
user@server1.example.com /srv/projects/* /home/david/testback/git 3
user@server2.example.com /srv/backup/* /home/david/testback/duffman 3
user2@server3 /media/storage2/* /home/david/testback/cartman 3 12500

View File

@ -26,6 +26,7 @@ sshkeyfile="$HOME/.ssh/id_rsa"
config=0
sshkey=0
deploy=0
list=0
options=$*
@ -51,6 +52,7 @@ usage()
echo " -h, --help show this message"
echo " -v, --version version information"
echo " -c, --config <configfile> alternate config file"
echo " -l, --list <listfile> list of sources and destinations"
echo " -s, --sshkey <sshkeyfile> alternate sshkeyfile"
echo " -d, --deploy <remote machine> deploy remote settings"
echo
@ -69,6 +71,21 @@ version()
preflight()
{
#amiroot
if [ $(whoami) != "root" ]; then
#echo "no root privileges available. continuing without."
:
fi
if [ -z $sourcepath ]; then
echo "aborting mission. no source path given."
exit 1
elif [ -z $destinationpath ]; then
echo "aborting mission. no destination path given."
exit 1
fi
if [ -r $sshkeyfile ]; then
#echo "sshkeyfile found"
:
@ -76,10 +93,13 @@ preflight()
#am i being run by cron?
tty -s
if [ $? -eq 0 ]; then
echo "im running in interactive mode"
echo "you have no ssh key configured."
#echo "i am running in interactive mode"
echo "you do not have a sshkey configured."
echo -e "do you want to create a new keypair? [y] \c"
read answer
if [ -z $answer ]; then
answer="y"
fi
if [ $answer == "y" ] || [ $answer == "Y" ]; then
#create keypair
:
@ -173,16 +193,18 @@ deploy()
}
debug()
sshbackup()
{
echo -e "debug output\n============"
echo "remote: $remotemachine"
echo "source: $sourcepath"
echo "destination: $destinationpath"
echo "versions: $versions"
echo "sshkey: $sshkeyfile"
echo "config: $configfile"
#debugging
#echo "source: $sourcepath"
#echo "destination: $destinationpath"
#echo "versions: $versions"
#echo "sshkey: $sshkeyfile"
#echo "config: $configfile"
}
@ -212,6 +234,9 @@ for option in $options; do
-c|--config)
config=1
;;
-l|--list)
list=1
;;
-s|--sshkey)
sshkey=1
;;
@ -238,6 +263,14 @@ for option in $options; do
elif [ $deploy -eq 1 ]; then
remotemachine=$option
deploy=0
elif [ $list -eq 1 ]; then
if [ -r $option ]; then
listfile=$option
list=0
else
echo "aborting mission. cannot read listfile. [$option]"
exit 1
fi
else
if [[ $option =~ ^-.* ]]; then
echo "aborting mission. unknown option given. [$option]"
@ -262,25 +295,34 @@ for option in $options; do
esac
done
if [ -z $sourcepath ]; then
echo "aborting mission. no source path given."
exit 1
elif [ -z $destinationpath ]; then
#destinationpath="."
echo "aborting mission. no destination path given."
exit 1
fi
if [ -r $configfile ]; then
if [ -r "$configfile" ]; then
source $configfile
fi
debug
#running preflight checks
#preflight
#sshbackup $sourcepath $destinationpath $versions
#read list if listfile is given
if [ -r "$listfile" ]; then
while read line; do
# find first letter
fletter=${line:0:1}
if [ -z $fletter ]; then
#skip line it's empty
:
elif [ $fletter = "#" ]; then
#skip line it's a comment
:
else
#creating variables
sourcepath=$(echo "$line" | awk '{print $1}')
destinationpath=$(echo "$line" | awk '{print $2}')
versions=$(echo "$line" | awk '{print $3}')
preflight
sshbackup
fi
done < $listfile
else
preflight
sshbackup
fi
# **** end of script ****