newbie attempting to create a script and seriously need help
hello friends. I am attempting to create an rsync backup script to backup three linux servers. I have tried for a while now with no real luck. I have figured out the commands that I want to use, but when it comes to adding them all together in the script, I have no idea. I have do many hours of research and have came up with nothing that I can really use, or at least lack the knowledge to use. Everything fails, mostly due to syntax errors, but I am new to bash scripting and new to Linux. I am now faced with a deadline and I am running out of time. Please help. I really want to learn and I will as soon as I get this project out of the way. I will post some information below about the servers and what I am looking to accomplish. If requested I will post some examples of what I have tried to do also.
Server Backup Info Devices being backed up Dns1: IP: 192.168.1.1 NetBios Name: dns1 Rsync version: 2.6.9 protocol version 29 Backup storage location on nas2: /raid0/data/backups/dns1/ Rsync command: rsync –avvh –exclude-from=rsync-exclude –progress –e ssh / root@192.168.1.100:/raid0/data/backups/dns1/ Services: IP: 192.168.1.7 NetBios Name: services Rsync version: 2.6.9 protocol version 29 Backup storage location on nas2: /raid0/data/backups/services/ Rsync command: rsync –avvh --exclude-from=rsync-exclude –progress –e ssh / root@192.168.1.100:/raid0/data/backups/services/ Inet1: IP: 192.168.1.2 NetBios Name: inet1 Rsync version: 3.0.8 protocol version 30 Backup storage location on nas2: /raid0/data/backups/inet1/ Rsync command: rsync –avvXh –exclude-from=rsync-exclude –progress –e ssh / root@192.168.1.100:/raid0/data/backups/inet1/ Storage device for backups Nas2: IP: 192.168.1.100 NetBios Name: nas2 Rsync version: 3.0.8 protocol version 30 Location of server backups: /raid0/data/backups/ What the script should do: 1) Upon starting the script it should display the present date and show a welcome message such as the example below: Welcome to the Server Backup Program Today is Wed Oct 31 10:34:22 CDT 2012 2) Next, this message would appear: What would you like to do? Backup or Restore? <Here I would select either B for Backup or R for Restore. If I were to choose Backup, it would ask: Would you like to backup a single server or multiple servers? If I choose single, by pressing S, it would ask: Which server would you like to backup? At this point, I could choose the server from a list by inputting a number or letter. Then it would display a message saying: You are about to backup <server name here>, are you sure you wish to continue? At this point I would select Y for Yes or N for No. Selecting Yes would run the command associated with that server (commands are listed above) and selecting No, would exit the program or revert back to the very start of the program. If I were to select M for multiple servers, it would ask: Which servers would you like to backup? <I would select them from a list by inputting the number that corresponds to those servers. After making my selection, the program would display a message saying: You are about to backup the following servers: <server1> <server2> <server3>, do you wish you proceed? I would select Y for Yes or N for No. Selecting Yes would run all three Rsync backup commands listed above. Selecting no would exit the program or revert to program start. If I were to choose Restore, it would ask: Which server would you like to restore? <At this point I would select the server from a list by inputting a number or letter. After making my selection, a message would be displayed: You are about to Restore <server name here>, are you sure you wish to continue? I would enter Y for Yes or N for No. Selecting Yes would run the script and selecting no would exit the program or revert back to the very start of the program. 3) After the process has completed, I would like a message to be displayed stating if the backup succeeded or if it failed. I would also need a log file to be created in the home directory. This is how I envision the Program: Welcome to the Server Backup Program Today is Oct 31 10:34:22 CDT 2012 What would you like to do? [B]ackup or [R]estore? Please press B for Backup or R for Restore. (I pressed B in this example) Would you like to backup a single server or multiple servers? Please press S for Single or M for Multiple. (I pressed S in this example) Please select a server to backup. 1 dns1 2 services 3 inet1 (I pressed 1 in this example) You are about to backup dns1, are you sure you wish to proceed? [Y]es or [N]o. Please enter Y for Yes or N for No. (I chose yes in this example) Now Backing up dns1……….. Progress And Verbosity Here (The script finishes & this message is displayed if successful) The backup operation was successful! A log file was created and placed in your home directory. (The program terminates) All responses will be greatly appreciated. Thanks. |
Quote:
|
I do not have any really relevant, just a bunch of different attempts at scripts to become familiar with some of the commands that I think I might would need to use. Like instance the select and case commands. None of which has actually been applied toward a backup script of any kind yet, as I am still trying to figure out how actually to use the commands. Would you like me to post these? There will be several.
|
Well, you have already your rsync commands (watch your options, it is --progress, not -progress), so all you need is the user interface. It should not really be a problem to generate some kind of basic skeleton for the script that prints out the information you want and waits for input, especially since you have an exact plan how the script should react.
May be you just begin with posting what you have done in that area. Please use code-tags for that to preserve the formatting and make your code more readable. |
It's not that difficult, and surely you should have been able to complete a few of the numbers:
1) Use echo and date. 2) Use a loop and nested case statements. 3) You use an 'if' statement to check that rsync succeeded, as well as the verbose option and pipe it to a file. Here's some links that may help: http://www.tldp.org/LDP/abs/html/index.html http://www.grymoire.com/Unix/ |
This was just an experiment, trying to figure out how to actually use the commands. It does not relate to my needs 100%, but I had to try something. As you can imagine, it did not work and has plenty of syntax errors, but I am completely new to all of this.
Code:
#!/bin/bash |
Syntax errors are easy to fix: I can spot
Other than that, your programme looks fine - you just need to create mybackup.sh. As for working out where the errors are, just run the programme and see what syntax errors it complains about. The errors normally aren't that helpful per se unless you're experienced, but they should tell you the line on which they occurred, so you can work out what you need to do from there. Hope this helps, |
thanks everyone.
|
case "$yn" in
The quotes force the script to make sense even if you arrive there with the variable not set. |
Hello Friends, I'm back with some new stuff. Can you help me figure this out?
Hello Again Friends
I'm still working on a backup and restore script. What I have ended up with is this. I have a task selector script that I've written. This script allows you too select either the backup or restore task. Once chosen, a secondary script pertaining to that task is launched. Say you chose the backup task, then the backup script launches. Here you are asked which server you want to backup or if you want to backup them all, then you are asked to confirm your choice. The problem is, I don't know how to fit the third script that I written into the second one to make it function correctly. Also, I don't know if I should write individual scripts for each server or have just one script with all the rsync commands for the different servers. I really have no idea what I'm doing. Can someone please help? I have given a good go. I will post my scripts below in order. Thanks Friends. PHP Code:
Code:
#!/bin/bash PHP Code:
Code:
#!/bin/bash PHP Code:
Code:
#!/bin/bash PHP Code:
Code:
#!/bin/bash If I knew what I was doing, I could have probably put all this together in one script, but I haven't gotten a clue. |
Code:
#!/bin/bash -vxe |
@unSpawn, I want to thank you for the info, but keep in mind I am just a newbie with all of this. Can you please explain to me, what it is exactly that you have posted?
Thanks |
This should be easier to read:
Code:
#!/bin/bash http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html http://www.tldp.org/LDP/Bash-Beginne...tml/index.html http://www.gnu.org/software/bash/man...ode/index.html http://www.grymoire.com/Unix/Sh.html http://mywiki.wooledge.org/BashFAQ http://mywiki.wooledge.org/BashPitfalls http://www.tldp.org/LDP/abs/html/ |
@unSpawn, thank you very much and yes that is much easier to read and I understand more clearly now. I will do as you have instructed and view the guides you have suggested. I will write back soon with an update on the knowledge that I have gained.
Thanks again unSpawn, it's people like you that make a difference!!! |
All times are GMT -5. The time now is 08:15 PM. |