Rsync over SSH incremental backups: test existence of a remote directory?
SlackwareThis Forum is for the discussion of Slackware Linux.
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.
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.
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.
(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.
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.
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.
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.
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:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.