LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 12-14-2015, 02:51 AM   #1
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,453

Rep: Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154
Rsync over SSH incremental backups: test existence of a remote directory?


Hi,

I've spent the weekend writing a script for automated backups with snapshot rotation using rsync over SSH. I got the initial idea from a chapter in O'Reilly's "Linux Server Hacks", which itself is an adaptation from this great online tutorial. My script works differently and doesn't split the hourly snapshots and the rotation, it's more of a KISS approach.

Here's my first draft:

https://github.com/kikinovak/microli.../lan/backup.sh

This first version already works on my local server, and now I'm trying to work out some details.

I want to test for the existence of a remote directory, and if this remote directory exists (on the client), a portion of the local script (on the server) will be executed. So far, here's what I got in a little test script.

Code:
ssh -o BatchMode=yes -o ConnectTimeout=5 root@alphamule [ -d /path/to/remote/dir ] ; echo $?
(Note: SSH key authentication is configured and works.)

This line returns 0 if the remote directory exists, and 1 if it doesn't. Now I wonder if I'm doing things in a uselessly complicated manner, or if there is a more simple way to do it.

Any suggestions?

Niki

Last edited by kikinovak; 12-14-2015 at 02:52 AM.
 
Old 12-14-2015, 03:37 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by kikinovak View Post
Code:
ssh -o BatchMode=yes -o ConnectTimeout=5 root@alphamule [ -d /path/to/remote/dir ] ; echo $?
This line returns 0 if the remote directory exists, and 1 if it doesn't. Now I wonder if I'm doing things in a uselessly complicated manner, or if there is a more simple way to do it.
Not sure why you need to simplify this further

What I would perhaps do is
Code:
if ssh -o BatchMode=yes -o ConnectTimeout=5 root@alphamule [ -d /path/to/remote/dir ]
then
    run some local script
fi
This will run the local script if both the ssh itself succeeds and the remote dir exists.

EDIT: I am a bit confused about client vs server here but hope I understood your question.

Last edited by berndbausch; 12-14-2015 at 03:40 AM.
 
1 members found this post helpful.
Old 12-14-2015, 05:13 AM   #3
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,453

Original Poster
Rep: Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154
Quote:
Originally Posted by berndbausch View Post
EDIT: I am a bit confused about client vs server here but hope I understood your question.
First of all, thanks for your suggestion. Let me clarify this a bit.

The script backup.sh is run on the server. That's the machine where all the backups are stored. It connects to all clients on the network, one after another, and does a backup of their data.

I'm not in my office, so I can't test it right now. I'll check it out this evening.

Cheers,

Niki
 
Old 12-14-2015, 07:26 AM   #4
Gerard Lally
Senior Member
 
Registered: Sep 2009
Location: Leinster, IE
Distribution: Slackware, NetBSD
Posts: 2,177

Rep: Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761Reputation: 1761
Quote:
Originally Posted by kikinovak View Post
Now I wonder if I'm doing things in a uselessly complicated manner ...
Yes you are. Why re-invent the wheel? rsnapshot is easy to set up and reliable. It's also easy for someone else to understand and maintain, something you can't necessarily say about a custom script. Since it's backups you're dealing with, you should play on the safe side and use tools already there and widely used - rsnapshot, or dar.
 
Old 12-14-2015, 11:14 AM   #5
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,453

Original Poster
Rep: Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154
Quote:
Originally Posted by berndbausch View Post
What I would perhaps do is
Code:
if ssh -o BatchMode=yes -o ConnectTimeout=5 root@alphamule [ -d /path/to/remote/dir ]
then
    run some local script
fi
This will run the local script if both the ssh itself succeeds and the remote dir exists.
Worked like a charm. Thanks!
 
Old 12-15-2015, 06:08 AM   #6
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,453

Original Poster
Rep: Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154
I've fleshed out the script, along with some explanations. Here's the new version:

https://github.com/kikinovak/microli.../lan/backup.sh

One problem I had to solve was backing up databases. As far as I know, the most simple way to do this is running a separate SQL dump on the client machines. Here's a little script I wrote for that:

https://github.com/kikinovak/microli...sql/sqldump.sh

Note: I know it's simple to dump all databases into one big SQL file. Except I prefer having my databases separate.

Feel free to give this a spin and report back.

Cheers,

Niki

Edit: here's what this looks like. See screenshot.
Attached Thumbnails
Click image for larger version

Name:	backups.jpg
Views:	22
Size:	157.1 KB
ID:	20293  

Last edited by kikinovak; 12-15-2015 at 11:11 AM.
 
  


Reply



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
incremental backups by using rsync acidrop Linux - Server 5 12-06-2012 10:54 AM
rsync incremental backups tqz Linux - Newbie 9 09-15-2012 03:22 AM
using rsync for incremental backups cccc Linux - Server 5 01-29-2010 06:02 AM
LXer: Create Incremental Snapshot-style Backups With rSync And SSH LXer Syndicated Linux News 0 08-13-2006 08:21 PM
Rsync for incremental backups? Phaethar Linux - Software 3 12-04-2003 01:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 03:40 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration