Automated remote backup of laptop using RSnapshot
Hi! I'm searching for real Linux Gurus! I have a machine on my network and that machine is a mass storage server that I will eventually use as a media server (to stream movies, videoclips and music on my home theater system). I use slackware 13 on ALL of my machines.
I am trying to automate the backup of the "/home" folder of my laptop onto the mass storage server. I currently use rsnapshot and it works great, but I would like to automate the whole process, even if I am not home or in front of my machines... basically, I assume that is possible and I am sure some of you guys already doing this!!! Here's what I imagined (in pseudo code): 1) Poll if server is active (up); 1.1) If not: 1.1.1) Wake up the server (WOL); 1.1.2) Wait for the server to boot; 1.1.3) Confirm the server has made it to the login prompt (normal boot); 1.1.3.1) If not, send an alarm via email; 1.1.3.2) If so, continue to step 1.2.1 (below) 1.2) If so: 1.2.1) Mount NFS share on local directory; 1.2.2) Rsync /home folder on NFS share; 1.2.3) Unmount NFS share; 1.2.4) Generate confirmation of successful completion on syslog server (same machine as NFS share) 2) If currently between 10PM and 5PM: 2.1) Shutdown server (means that I'm either sleeping or not home); else 2.2) If server was down; 2.2.1) shutdown server (means that I'm not home); else 2.3) If server was up: 2.3.1) Keep it up! (means that I'm using it for media streaming); Any idea or recommendations, please share with me!! Thanks!! |
Real Linux gurus can be found here :)
Meanwhile, the high-level pseudo-code looks do-able and bash script would be suitable (as would several other scripting languages -- which do you know best?). Regards "Poll if server is active" it might be simpler just to try mounting the NFS share because that is the functionality you want. By its network activity trying to mount the NFS share would effect "1.1.1) Wake up the server (WOL)" so this method would save a specific step to do so (KISS). The script could sit in a time delayed loop trying mount the NFS share. If successful immediately note that server was not down. If not successful after a reasonable elapsed time do "1.1.3.1) If not, send an alarm via email" and give up. For each part of the script I would become familiar with the necessary commands by running them at the command line and then program them into the script. No point in writing more until you tell us which parts you know how to do. For the rest we can recommend some approaches and give you some keywords to search on and learn as required. LQ seldom writes scripts to order; we prefer to help people do it themselves. Give a man a fish ... |
catkin, many thanks for your reply!
I guess I posted without indicating some valuable info.... I'm sorry about that. Yes I was refering to a bash script, basically a .sh file. Except that, in linux I dont know any other languages and in fact I'm pretty poor at bash scripting. I have no idea how to program logic loops such as if conditions, else, and simple loops (while)... As for the individual commands and their usage, here's what I know (at least entering these in a terminal ): Poll if server is active = I guess a simple ping would do? The thing I dont know is how to interpret the answer received from that command (no ping VS ping ?) Wake up the server (WOL) = I have installed WOL on my laptop so a simple wol MAC_ADDRESS_OF_SERVER would do? Wait for the server to boot = Sleep ?? Confirm the server has made it to the login prompt (normal boot) = I have absolutely no idea how to do that! What I'm trying to do here is to make sure the server booted up normally and has made it to the login prompt (in case it freeze during kernel load, kernel panics, corrupted partitions, etc, only god knows what can go wrong!) If not, send an alarm via email = No idea!! Mount NFS share on local directory = I know how to do that (mount -t nfs IP_ADDRESS_OF_SERVER:/path/to/mount/directory Rsync /home folder on NFS share = rsnapshot will take care of that! Unmount NFS share = umount /local/mount/point Generate confirmation of successful completion on syslog server (same machine as NFS share) = No idea!! That is, at least for me, the black magic section : ==> If currently between 10PM and 5PM: = No idea!! Shutdown server = halt? Any better way to shutdown a slackware machine? If server was down = No idea!! How do you validate if the machine was initially powerred up through step WOL or was already up? shutdown server = same as above If server was up = No idea!! How do you validate if the machine was initially powered up through step WOL or was already up? Keep it up! = I should figure out this one! ;) I also forgot to mention that I dont know how to handle the potential prompts for passwords (either locally or remotely) from for example umount... normally only root can umount. Running this script as root would do it right? Thanks! |
Quote:
Overall, I suggest an iterative approach. Version one of the script could be just the basics, without bells and whistles. Once that is working, progressively add refinements in order of importance as determined by experience using the script. Two exceptions to that: error trapping and logging. Firstly developing a good error trapping and logging framework from the beginning will aid in debugging and troubleshooting. A clean implementation can be easily extended to emailing later. Secondly using a single function to exit the script. That would allow the script to undo changes it has made that should be undone and facilitates logging a final message; it is also useful during debugging when you will be running the script interactively and may want to stop it using Ctrl+C. |
catkin, I am building the script right now. I will let you know what happens soon!
Thanks! |
catkin, I have a hardcopy of Advanced Linux Programming by "New riders" do you know this book? is tha any good?
|
Quote:
|
Yeah I never really opened that book before, I tough it was for shell scripting.... sorry about that!
|
Hey catkin! Like I said, I am writing my script right now, and so far, I am pretty satisfied! some stuff works, some not ( was to be expected right!?)
I have a problem with polling the server to see if it is alive. Like you said in one of your earlier posts, I can ping the server and grab what the command returns and interpret in a case statement or an "if" ... Basically, I am using the following IF block to see if the machine is up & running (please note that $IP_BACKUP_SRV is a variable declared at the very beginning of the script and it is the IP of the server): Code:
if [ ping -c1 -w1 -q $IP_BACKUP_SRV >/dev/null = 1 ]; then Code:
./rsnapshot_script.sh: line 20: [: too many arguments ??? Whats going on? If I understand correctly, this is a string comparison (not arithmetic right?) and a equal sign is supposed to do? If it was an arithmetical comparison, I would have to use -eq ? Thanks !!! |
Try using the exit status of the command.
Code:
ping -c1 -w1 -q $IP_BACKUP_SRV &>/dev/null |
it works perfectly! I am still workingon the script but so far it looks good!
|
Hey guys!
I have a problem with a portion of my backup script. The following code should verify what time it is (on the local machine) and then if the time is between 4PM (16:00:00) and 10PM (22:00:00) keep the server alive, if not, shut it down... When I run the code, it always decide to shut down the server like if it was either before 4pm or past 10pm... Why? for example, I tried the code at 8pm and it didnt work. Code:
date +%H%M%S &>/dev/null Thanks! |
Quote:
Code:
current_time=$(date +%H%M%S) |
I kinda have more questions that are related to this thread and did not want to open a new thread for the same stuff, so I marked this thread Unsolved.
My new question is pretty straight forward. I have 3X 5.25 SATA removable bays with hard drives in it. I am working on a new script to manually backup some very important data to those drives. Basically, to eliminate risks of burning the HDD's, or accidentally (either by me or my scripts) destroy data, I normally keep those drives offline, i.e. unpowered. The enclosures are Vantec EZ swap and require a key to turn them on/off. Once it is turned on, Slackware see them without a glitch. My script will basically display a message to warn that the backup is about to happen, then once the user click the OK button, mount the partition to a local folder and then backup the data. The partition will then be unmounted and a new message will be displayed to ask the user to "unplug" the HDD. Cron will take care of the schedule. Basically, in pseudo code: Code:
1-Verify if sdd is connected (powered)... If so, procee to #2, else display message box "The HDD is not connected" The second question is more complicated. I want the script to display the messages boxes (Please plug the HDD & You can now unplug the HDD) to a different display (i.e. my laptop). The reason is because the script will run on my server that has no monitor... any idea? Thanks!! |
bump!!! nobody got an idea on this one?
|
All times are GMT -5. The time now is 08:55 PM. |