LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 11-04-2007, 11:06 PM   #1
luis14
Member
 
Registered: Jun 2006
Location: Des Moines
Distribution: Debian Lenny
Posts: 59

Rep: Reputation: 15
Help with rsync command (or script) multiple file backups


These are the commands I use to back up specific files from my home directory to another machine. I have to enter them one at a time and am prompted for my password after each command.

I remember reading a forum post somewhere describing how to link commands like these (something to do with &&).
Code:
rsync -e ssh -avz --delete-after daniel@10.0.0.7:/home/daniel/pictures /home/daniel

rsync -e ssh -avz --delete-after daniel@10.0.0.7:/home/daniel/video /home/daniel

rsync -e ssh -avz --delete-after daniel@10.0.0.7:/home/daniel/music /home/daniel

rsync -e ssh -avz --delete-after daniel@10.0.0.7:/home/daniel/documents /home/daniel

rsync -e ssh -avz --delete-after daniel@10.0.0.7:/home/daniel/programs /home/daniel
Anybody know how to convert this to one command or script so I can enter my password once and walk away while the backups are performed?
 
Old 11-05-2007, 07:18 AM   #2
0.o
Member
 
Registered: May 2004
Location: Raleigh, NC
Distribution: Debian, Solaris, HP-UX, AIX
Posts: 208

Rep: Reputation: 35
Quote:
Originally Posted by luis14 View Post
These are the commands I use to back up specific files from my home directory to another machine. I have to enter them one at a time and am prompted for my password after each command.

I remember reading a forum post somewhere describing how to link commands like these (something to do with &&).
Code:
rsync -e ssh -avz --delete-after daniel@10.0.0.7:/home/daniel/pictures /home/daniel

rsync -e ssh -avz --delete-after daniel@10.0.0.7:/home/daniel/video /home/daniel

rsync -e ssh -avz --delete-after daniel@10.0.0.7:/home/daniel/music /home/daniel

rsync -e ssh -avz --delete-after daniel@10.0.0.7:/home/daniel/documents /home/daniel

rsync -e ssh -avz --delete-after daniel@10.0.0.7:/home/daniel/programs /home/daniel
Anybody know how to convert this to one command or script so I can enter my password once and walk away while the backups are performed?
You can string the commands together via either && or ; or even use ||. && tells it to execute the first one and the second only if the first executes successfully. ; will execute the next command no matter what. || will execute one or the other. If the first command executes fine, the second will be ignored. However, if the first fails, the second will be executed.

You can also avoid the password prompts via the use of ssh keys. Google for ssh-keygen (or read the man page).
 
Old 11-05-2007, 07:32 AM   #3
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,498

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
You may also consider to use a for loop, as in
Code:
#!/bin/bash
dirlist="pictures video music documents programs"

for dir in $dirlist
do
   rsync -e ssh -avz --delete-after daniel@10.0.0.7:/home/daniel/$dir /home/daniel
   test $? -eq 0 || break
done
In this way you have just to edit the list of directories to backup. The test part simply stats "if something goes wrong with the previous command break the cycle", so you can stop the backup process and investigate about the failure.
 
Old 11-08-2007, 10:07 PM   #4
luis14
Member
 
Registered: Jun 2006
Location: Des Moines
Distribution: Debian Lenny
Posts: 59

Original Poster
Rep: Reputation: 15
Works beautifully! Thanks for sharing your knowledge.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rsync for incremental backups Meson Linux - General 1 10-30-2007 09:44 AM
Rsync backups gabsik Linux - General 3 11-24-2006 07:14 PM
Rsync Errors during backups shawnbishop Linux - Software 4 05-18-2006 03:26 AM
Rsync backups gabsik Linux - Networking 1 03-30-2006 10:31 AM
Backups with rdiff - how different from rsync? Donboy Linux - Software 1 07-30-2004 10:54 PM


All times are GMT -5. The time now is 03:09 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration