|
Sooner or later it happens to all of us. Your computer crashes, you have a virus, the server where you have a shell goes down, etc etc. Prevention is easy, but still, most of the times we dont take the few minutes that are necessary to backup our valuable data.
loosing your data is easy
I myself had lost much work in the dissapearance of a shell provider once. I make much use a of a darkbot in one of my channels. Darkbot are bots that react to text spoken in the channel, and thus are great for automatic answering of FAQ's etc. And, each day I spend about 30 minutes to a hour adding new data to the bot. As you can see, something you want to backup reguraly. Well, at some point the provider got continuesly attacked with DDoS, and in the end, to protect his customers who had websites there, decided to stop supporting IRC completely. I never had the chance to go on the shell, and download the databases
fortunally, backing up is as well
That was my lesson. I guess everyone will have similar experiences at some point. So, it was time to automate some things. At this moment I am running two scripts, one on my Linux machine who makes nice backups of each bot's directory(2 eggdrops, and a darkbot) at 5am in the morning, complete with a date in the name (great if you find out after a week you screwed up something, now you have a backup of your bot from all kinda points in time!). At 5.15am my Windows2000 machine ftp's to my Linux machine to retrieve the bots, and places them in my backup directory.
setting up the *nix side
For clarity, we will assume you have a directory called eggdrop in your home directory on the shell you want to have backupped each day. Paths and names used in this tutorial might be different from your situation, I will explain where necessary to find out what your variables are.
First we need to collect some data. The script will be made in the bash language, and we need to know where bash can be found on the system. Usually this is /bin/bash To check if this is also the case on your shell by typing: which bash
Next we need to know the path to the directory of your eggdrop (or other bot/program you want to backup). To do this, use cd to enter your eggdrop directory, and next, type: pwd For this tutorial we will asume the path pwd gave is: /home/user/eggdrop
Return to your home directory by type cd ~ Before we are going to write the actual script, we are going to make a directory first where we are going to store the backups, to do this, type: mkdir backups
Now on to the actual script. Type: pico backupBot This will open up pico, a easy to use text editor. To learn more about its features, check the unix primer tutorial.
On the first line you put the path to bash. This way we provide what language we use. The path used here is the usual path in Linux, for *BSD its probally /usr/local/bin/bash. Use whereis bash to find the location on your system if needed.
#!/bin/bash
Next we are going to delete the old backups from the backup directory. After all, we dont want to exceed our quota for the shell space! And since we will download the bots to the Windows machine, there is no need to keep them here as well. Type:
rm /home/user/backups/bot*
Note the * behind the file's name. Trailing the word "bot" we will insert a date. To let the script delete the file, we need to add a wildcard for that part of the name.
Almost done now. All thats left is making a backup of the eggdrop directory, and putting it in de backups directory, complete with a date in the name. We can do both in the same line, type:
tar czfp /home/user/backup/bot_`date +%d_%m_%y`.tgz /home/user/eggdrop/
Let's take a closer look at that line, after all, this is suppose to be a tutorial, so the intention is you learn something out of it. Note the `date +%d_%m_%y` in the line. This part is taking care of adding the date into the final archive, which will look like: bot_09_08_01.tgz Note how that part is enclosed in ``. Using these we can insert commands that will be perform before the tar command. If you would type date +%d_%m_%y on the shell, you would get a date back like: 12_8_01 As you see, this will return a nice date for the archive's name! Use man date if you want learn more about date.
So, tar czfp will create us a file called bot_`date +%d_%m_%y`.tgz into the directory /home/user/backup/ And that backup will contain all the files that are in /home/user/eggdrop/ Easy enough! (yes, dont be ashamed if you need to read this a second time, I did 4 times to make sure I put all facts right ;))
Well, we are done with the script now. Type ctrl x to exit pico, and answer yes to save the file. If you followed all steps carefully, you should have a file in your home directory called backupBot. The next step is to make this file executable. To do this we type: chmod +x backupBot
To test if the script is working correctly type: ./backupBot Note the leading "." it has to be there to function. Now type cd backup to enter the backup directory, and type ls to take a look at the directories contents. Its should contain a file with the name bot_theDate.tgz. If not, then you need to go back into pico and edit the backupBot script. Be aware, *nix systems are case sensitive, so make sure you dont have any errors there.
If the script made a bot_date.tgz backup into the backup directory, then there is only one thing left. And that is to enter a entry into the crontab of the server, so your backup script will be executed at the time interval you specify. For this tutorial we are going to let the crontab execute the script at 5am in the morning. Remember: the server might have a totally different time as you have due to it being on the other side of the world... But, you know the date command now to see what time it is on the server by now ;)
To start editing the crontab type: export VISUAL=pico; crontab -e It will open crontab into pico so we can edit it easily. In pico enter the next line:
00 05 * * * /home/user/backupBot
Congrats, you are all done concerning the shell part of this tutorial.
now, onto uncle microsofts side of the tutorial
I will give a few hints regarding to the Windows side. Problem is , by now there are quite a few flavours of windows, all with different ways of handling scheduled events (microsofts "crontab"), and we need to make a script for the FTP client we use on windows. And the scripting commands can be different from FTP client to FTP client. Check out the help files that came with the program. Lets take a look at the script I made for the FTP client I use, LeapFTP:
CONNECT:my.shell.com:myLogin:myPass:21
Connect to my shell using my login name and password on port 21.
CD-R:/home/user/backups
Change the remote directory to the directory with the backup.
CD-L:E:\backupBots\
Change the local directory where I want to save my backupped bot.
GET:*.tgz
Download all files that end with .tgz
DISCONNECT
Guess
EXIT
Guess again
END
Yup, you got it right the first time!
I saved this file as botscript.txt into the same directory as where I download my backupped bots to: E:\backupBots\botscript.txt To make windows2000 to perform this script at 5.15am each morning, I open the Schedules Tasks panel. You can find that in: Start --> Programs --> Accessoiries --> System Tools --> Schedules Tasks (pfew).
Click the Add Scheduled Task icon. Next select the FTP's client name from the list, or use browse to select it and click next. Give the Task a name, and select daily, click next. For the start time, choose 5.15am, click next. Next enter your login and password for the windows user, and click next again. Select Open advanced properties fir this task when i click finish, and click finish.
Almost done now. In the new panel that opens up we need to add the path to the script that LeapFTP needs when it is started up by Scheduled Tasks. Edit the line Run in such a way, that it will display:
"C:\Program Files\LeapFTP\LeapFTP.exe" script=E:\backupBots\botscript.txt
Done! As you see it is not hard. And the *nix script is easy to expand with more directories. Have fun exploring!
? Discuss This Article here.
|