Bash script to back up with rsync


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash script to back up with rsync
# 1  
Old 11-13-2009
Bash script to back up with rsync

I'm trying to write a script to back up with rsync, the script I am posting below:

Code:
nomServer="shiva horus isis"
dirshiva="/etc /faturamento"
shivaListExc="/usr/local/bin/shivaListExclRsync"
dumpDir="$dumpFile/Shiva"
dateBkp=`date +%A`

for nServer in ${nomServer}
do
        dirServer="$dirBkp/$nServer"
        if [ ! -d $dirServer ]
        then
                mkdir $dirServer
        fi
        
        for sDir in dir${nServer}
        do
                rsync -C \
                -D \
                --recursive \
                --update \
                --links \
                --perms \
                --acls \
                --xattrs \
                --owner \
                --group \
                --times \
                --verbose \
                --progress \
                --partial \
                --numeric-ids \
                --specials \
                --exclude-from=${nServer}ListExc \
                $nServer:$sDir $dirServer

                dumpDir="$dumpFile/$nServer"
                if [ ! -d $dumpDir ]
                then
                        mkdir $dumpDir
                fi

                if [ ! -d $dateBkp ]
                then
                        mkdir $dumpDir/$dateBkp
                fi

                tar -zcvfp --atime-preserve --remove-files /$dumpDir              /$dateBkp$sDir.tar.gz /$dirServer$sDir
        done
done

my question:

Code:
dirshiva="/etc /faturamento"
shivaListExc="/usr/local/bin/shivaListExclRsync"



the first variable is an array but when I called it in for is failing.

Code:
for sDir in dir${nServer}



I need this variable to return the value "dirshiva", there's any way to do this? I tried in many ways and I confess that I had no success.

if anyone has any ideas, I am grateful.

att,

Amilcar

Last edited by ajmoreti; 11-13-2009 at 10:08 AM.. Reason: added code tags
# 2  
Old 11-13-2009
The posts should be in English only. Please edit and translate your post.

Thank you!
# 3  
Old 11-15-2009
I run your code in bash and get the result. Which shell do you use for this code?

Code:
$ cat urfile
nomServer="shiva horus isis"
dirshiva="/etc /faturamento"
shivaListExc="/usr/local/bin/shivaListExclRsync"
dumpDir="$dumpFile/Shiva"
dateBkp=`date +%A`

for nServer in ${nomServer}
do
        dirServer="$dirBkp/$nServer"
#        if [ ! -d $dirServer ]
#        then
#                mkdir $dirServer
#        fi

        for sDir in dir${nServer}
        do
          echo $sDir
        done
done

$ ./urfile
dirshiva
dirhorus
dirisis

You can turn on -x to debug your script, or add some echo commands to verify as the sample showed above.
# 4  
Old 11-16-2009
The solution I found was that:

nomServer="shiva deva"
dirshiva="/etc /home /lean /ordensProd /otimizador /pcp /qualidade /sgq /srf"
dirdeva="/etc /usr/local/bin /totvs/apo/logix /totvs/bin/appserver"
for nServer in ${nomServer}
do
dirServer="$dirBkp/$nServer"
if [ ! -d $dirServer ]
then
mkdir $dirServer
fi

listExclude="/usr/local/bin/${nServer}ListExclRsync"
for sDir in $(eval echo \$dir${nServer})
do
rsync -C \
-D \
--recursive \
--update \
--links \
--perms \
--acls \
--xattrs \
--owner \
--group \
--times \
--verbose \
--progress \
--partial \
--numeric-ids \
--specials \
--exclude-from=$listExclude \
$nServer:$sDir $dirServer

dumpDir="$dumpFile/$nServer"
if [ ! -d $dumpDir ]
then
mkdir $dumpDir
fi

if [ ! -d $dateBkp ]
then
mkdir $dumpDir/$dateBkp
fi

tar -zcvf $dumpDir/$dateBkp$sDir.tar.gz /$dirServer$sDir --atime-preserve -p --remove-files
done
done

tanks,
Amilcar
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Terminal running bash/rsync script does not close with exit (MacOS High SIerra)

Hello, I am running a bash script to do an rsync back on a computer running MacOS High Sierra. This is the script I am using, #!/bin/bash # main backup location, trailing slash included backup_loc="/Volumes/Archive_Volume/00_macos_backup/" # generic backup function function backup {... (12 Replies)
Discussion started by: LMHmedchem
12 Replies

2. Shell Programming and Scripting

Rsync in bash script doesn't work even after placing pub key in target server

Hello Friends, My bash script is like this #!/bin/bash # request Bourne shell as shell for job #$ -S /bin/bash # assume current working directory as paths #$ -cwd #$ -N rsync-copy # # print date and time date rsync -rltD --progress "ssh -i /home/myname/.ssh/id_rsa"... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

3. OS X (Apple)

Rsync for back up, external HD

Hello all! I am quite unsure with all options of rsync. Here my backup configuration: I am on Mac X (10.8) and want an exact copy of my HD to an external HD. I formatted the new USB drive with Mac OS extended (Journaled, Encrypted) and made in my shell the following command and got the... (9 Replies)
Discussion started by: marek
9 Replies

4. Shell Programming and Scripting

Rsync script to rewrite suffix - BASH, awk, sed, perl?

trying to write up a script to put the suffix back. heres what I have but can't get it to do anything :( would like it to be name.date.suffix rsync -zrlpoDtub --suffix=".`date +%Y%m%d%k%M%S`.~" --bwlimit=1024 /mymounts/test1/ /mymounts/test2/ while IFS=. read -r -u 9 -d '' name... (1 Reply)
Discussion started by: jmituzas
1 Replies

5. Shell Programming and Scripting

Bash shell script: Str(007) to int(7),increment it(8) & convert back to string(008)

Hi, I have the following requirement. There will be following text/line in a file (eg: search-build.txt) PRODUCT_VERSION="V:01.002.007.Build1234" I need to update the incremental build number (eg here 007) every time I give a build through script. I am able to search the string and get... (4 Replies)
Discussion started by: drwatson_droid
4 Replies

6. Shell Programming and Scripting

Bash Script Help...search then read from file: change text and pipe back...

Hello, I am trying to make a bash script that can pull data from a file and then change one part of said data. I want to search by username and pull the full line. That way there is a way to replace just one part of that line then return it back to the file. My Data is stored like: ... (1 Reply)
Discussion started by: serverfull
1 Replies

7. Shell Programming and Scripting

Reading output from terminal back into bash script

How can I get a bash script to wait and read and count $i messages that a running program (drbl clonezilla) sends to the console (terminal) and only then move on to the next line in the script when the count is matched (the next line is the last line of the script and is a reboot)? The script... (0 Replies)
Discussion started by: dp123
0 Replies

8. Shell Programming and Scripting

rsync bash php

Hello, I have a bash script update.sh that contains rsync --delete -avz -e ssh ${files} root@64.XX.XX.XX:/websites/red/ when I use that script ./update.sh as root, it works like a charm as I set up the private/public key properly. When run from a php script through the apache webserver <?php... (10 Replies)
Discussion started by: JCR
10 Replies

9. Shell Programming and Scripting

Bash rsync but move not delete

There might be an easy solution to my problem, or maybe not, but here it is. I am trying to rsync a Volume with 1.5 terabytes of data and send it via fibre channel to a raid array. Now normally when I rsync it scans through everything and, before copying anything, deletes any files that have... (1 Reply)
Discussion started by: Movomito
1 Replies

10. UNIX for Dummies Questions & Answers

rsync back?

Hi, I am in the process of developing backup script using rsync, my code is bellow: EXCLUDE_DIR="/home/kannanpg/mscdr/src/ex1" rsync -az -e ssh -v --exclude $EXCLUDE_DIR --delete $HOSTTOBACKUP:$SOURCE $DR_BACKUP_DIR/daily.0 >$tempfile 2>&1 even my exclude dir is coping.. what is wrong in... (1 Reply)
Discussion started by: redlotus72
1 Replies
Login or Register to Ask a Question