Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've a script to backup some directories in my home.
This is the script (abridged):
Code:
#!/bin/bash
SOURCE="{argomentare/*,articoli/*}"
TARGET="/media/CORSAIR"
date=`date "+%y-%M-%D"`
TAG="backup"
if mount | grep -q $TARGET
then
echo "Il disco è montato: eseguo il backup"
logger Inizio backup di $SOURCE per `hostname` -t $TAG
rsync -rvu --progress $SOURCE $TARGET/
RSYNCERR=$?
logger Fine backup per `hostname`: rsync ha restituito $RSYNCERR -t $TAG
exit 0
else
echo "Il disco non è montato"
logger Impossibile eseguire il backup di `hostname`: disco non montato -t $TAG
exit 1
fi
but it gives me this error:
Code:
samiel@debian:~$ bash -x backup.sh
+ SOURCE='{argomentare/*,articoli/*}'
+ TARGET=/media/CORSAIR
++ date +%y-%M-%D
+ date=12-29-08/10/12
+ TAG=backup
+ mount
+ grep -q /media/CORSAIR
+ echo 'Il disco è montato: eseguo il backup'
Il disco è montato: eseguo il backup
++ hostname
+ logger Inizio backup di '{argomentare/*,articoli/*}' per debian -t backup
+ rsync -rvu --progress '{argomentare/*,articoli/*}' /media/CORSAIR/
sending incremental file list
rsync: change_dir "/home/samiel//{argomentare/*,articoli" failed: No such file or directory (2)
sent 12 bytes received 12 bytes 48.00 bytes/sec
total size is 0 speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1070) [sender=3.0.9]
+ RSYNCERR=23
++ hostname
+ logger Fine backup per debian: rsync ha restituito 23 -t backup
+ exit 0
Assuming not, you then need to ask yourself what would you type on the command line? This will then help with what you need to store in the variable.
Initially I would probably suggest using an array.
If the arguments are to be evaluated locally, by bash, then the wild cards and brace expansion shouldn't be in quotes.
If you precede a connand with set, you can examine the arguments $1, $2, etc. to verify what arguments the command sees after bash performs the various expansions.
Il I had all this theorical knowledge,
I would be able to write that array.
If I ask for an example, that is because
I'm not able to write this script by myself...
I don't need to backup all my home,
but only some selected directories.
Is there no way to tell bash to select them
in a short way? You suggested me some solutions,
but I dont understand what is the more convenient,
and in any case I've no experience
in bash programming... Any concrete example
will be welcome :-)
You are missing my point. I am not asking you to write arrays or any more code. What I am asking is for you to write the command line entry needed to perform the task you are attempting.
For example:
Code:
rsync -rvu --progress old_dir/* new_dir
I am not confirming the above works, but my main point is, what does work and do you really require the wildcards?
#!/bin/bash
SOURCE="{argomentare,bibliografie,documenti}"
TARGET="/media/CORSAIR" # Directory di destinazione dove cui fare il backup
date=`date "+%y-%M-%D"` # Data del backup; %H_%M per avere anche l'orario
TAG="backup" # tag dei log scritti in /var/log/messages
if mount | grep -q $TARGET
then
echo "Il disco è montato: eseguo il backup"
logger Inizio backup di $SOURCE per `hostname` -t $TAG
rsync -rvu --progress $SOURCE $TARGET/
RSYNCERR=$?
logger Fine backup per `hostname`: rsync ha restituito $RSYNCERR -t $TAG
exit 0
else
echo "Il disco non è montato"
logger Impossibile eseguire il backup di `hostname`: disco non montato -t $TAG
exit 1
fi
bacause it tells:
Code:
samiel@debian:~$ bash -x backup.sh
+ SOURCE='{argomentare,bibliografie,documenti}'
+ TARGET=/media/CORSAIR
++ date +%y-%M-%D
+ date=12-34-08/12/12
+ TAG=backup
+ mount
+ grep -q /media/CORSAIR
+ echo 'Il disco è montato: eseguo il backup'
Il disco è montato: eseguo il backup
++ hostname
+ logger Inizio backup di '{argomentare,bibliografie,documenti}' per debian -t backup
+ rsync -rvu --progress '{argomentare,bibliografie,documenti}' /media/CORSAIR/
sending incremental file list
rsync: link_stat "/home/samiel/{argomentare,bibliografie,documenti}" failed: No such file or directory (2)
sent 12 bytes received 12 bytes 48.00 bytes/sec
total size is 0 speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1070) [sender=3.0.9]
+ RSYNCERR=23
++ hostname
+ logger Fine backup per debian: rsync ha restituito 23 -t backup
+ exit 0
whre you can see in particular:
Code:
rsync: link_stat "/home/samiel/{argomentare,bibliografie,documenti}" failed: No such file or directory (2)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.