Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › Bash syntax issue with rsync options.
New Posts  All Forums:Forum Nav:

Bash syntax issue with rsync options.

post #1 of 5
Thread Starter 
Got the idea over on LQs to use a variable for the options to a command. This appealed to me for this script.
Script (Click to show)
Code:
#!/bin/bash
#Name = mybackups
#Author = Tadaen Sylvermane
#Purpose = Cron backups - Usb drives
#Last Edit = 2014/5/6 - 1427

##### begin script #####

if ! mountpoint -q $2 ; then
        mount $2 && rsync -au --include-from="${1}.include" --exclude="/*" $1 $2 --delete
else
        rsync -au --include-from="${1}.include" --exclude="/*" $1 $2 --delete
fi

##### end script #####

The above script works fine. Have the same rsync lines repeated twice. Decided to change it to a variable as such to simplify things a bit such as turning on and off verbose flag for testing / checking things with it.
Modified to variable (Click to show)
Code:
#!/bin/bash
#Name = mybackups
#Author = Tadaen Sylvermane
#Purpose = Cron backups - Usb drives
#Last Edit = 2014/5/6 - 1427

##  variables ##

OPT="-au --include-from='${1}.include' --exclude='/*' $1 $2 --delete"

##### begin script #####

if ! mountpoint -q $2 ; then
        mount $2 && rsync $OPT
else
        rsync $OPT
fi

##### end script #####

Problem is it throws this error.
Code:
jason@failbox:~$ mybackups /media/data/ /media/backups/fdd
+ mountpoint -q /media/backups/fdd
+ rsync -au '--include-from='\''/media/data/.include'\''' '--exclude='\''/*'\''' /media/data/ /media/backups/fdd --delete
rsync: failed to open include file '/media/data/.include': No such file or directory (2)
rsync error: error in file IO (code 11) at exclude.c(1179) [client=3.1.0]
+ set +x

I'm doing something wrong, not sure. The file is there and as said above the script works before I change it to a variable.
Code:
jason@failbox:~$ ls -al /media/data/ | grep include
-rw-r--r--  1 jason jason   119 May 13 08:00 .include

Please advise to what I'm doing incorrectly.
Edited by Tadaen Sylvermane - 5/15/14 at 10:53am
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
post #2 of 5
Looks like it could be an issue with quotes. The error message is saying that the single quotes are part of the file name.
post #3 of 5
Thread Starter 
Removing the quotes around the --include and --exclude and it's working. Thanks much.
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
post #4 of 5
Personally I think the new version of the script is worse than the old. I'm all for having parameters passed as variables, but in this instance your source / dest / include parameters are already variables to begin with, so you're making things more complex by then adding those variables into another variable. And since it's only a short script with one instance of rsync, you don't gain anything from the additional complexity (if anything, you just add in more potential bugs - such as escaping white space).
post #5 of 5
Thread Starter 
Is 2 instances of rsync. Both identical hence figured would be simpler to have one option line instead of keeping up 2 with 2 of them? I guess its a toss. It does add some complexity but also makes it simpler at the same time in my eye. Just figured if I wanted to tinker with it its easier to modify 1 rsync line than 2 through the script (even though the script isn't complicated).

I'm all for learning so don't hold back. If I'm wrong correct me please.
Edited by Tadaen Sylvermane - 5/16/14 at 11:53am
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix
Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › Bash syntax issue with rsync options.