Scheduling Backups

mkoreen

Joined
May 21, 2009
Messages
7
Likes
0
Points
0
#1
At my work we have just recently started using Elastix, switched from trixbox mainly because the backup module that Elastix has is much more robust and covers almost all the configuration of the server. The only problem is that it doesn't have any way to schedule backups. Freepbx does have a backup module with scheduling, but its backup doesn't cover all the services and configurations that the backup module does.

Originally I was going to just make a cronjob that sent the html POST to the backup module to tell it to make a backup, but after looking into that and the amount of data I'd have to send to trigger a full backup, I shelved that idea.

Instead I've written a perl script that does basically the same thing as the backup module that comes in Elastix, except of course you can run it from the command line instead of having to use the web interface. This makes it possible to put it in a cronjob or anything else to have regular backups created automatically. The files made can be selected and restored via the web interface.

Please note there's not a lot of error correction in this script. If commands fail it probably isn't going to tell you about it. It's the first revision and I'll be making a better version in the future, but for now it works and is running on my system. I thought it might be useful to others so I am posting it.

-Marie http://forum.elastix.org/old_files/backup.tgz
 

hpwr

Joined
Jun 4, 2009
Messages
17
Likes
0
Points
0
#2
Thank you very much, I was searching for this and will give it a try later.

This feature, should be integrated into Elastix, I think it is a very usefull option.

And after this, uploading the whole backup file to a remote location via FTP or so should be also integrated, so you can have periodic full backups or your customers PBX´s and could supply a fast replacement HDD or full machine for minimum down-time.

I´ll try your script and combine it with a FTP upload script and see what happen.

Best regards !
 

raj

Joined
Apr 19, 2009
Messages
149
Likes
0
Points
0
#3
If you could post some step by step for newbies like me if im the only newbie here then for me please
 

mkoreen

Joined
May 21, 2009
Messages
7
Likes
0
Points
0
#4
Instructions:

1. Untar the script.
2. Put it somewhere on the host.
3. Edit the file and change any configuration options that you want to change.
4. Edit /etc/crontab and add a line like the following:

02 3 * * * root /root/backup.pl

That would make it do a backup at 3:20am every day.
 

hpwr

Joined
Jun 4, 2009
Messages
17
Likes
0
Points
0
#5
Hello !

I´ve tested some things and the script is working good so far, I´ve added some lines to the script to upload the resulting file to a FTP server, and also changed the filename including the machine hostname for better orgasnisation on the ftp-server.

I don´t know much about programming languages so I used the c&p method B)

Here the instrucions I wrote and used;

1: Install wPut ( wput.sf.net )
# wget http://freefr.dl.sourceforge.net/source ... -0.6.1.tgz
# tar -xzf wput-0.6.1.tgz
# cd wput-0.6.1
# ./configure; make
# make install

2: Configure Hostname
# vim /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=elastix-name
GATEWAY=192.168.0.1

# hostname elastix-name

3: Edit backup.pl and edit your FTP server information...
my $ftp_destination = 'ftp://usuarname:password@server:port';

4: Copy backup.pl to your elastix machine ( /root/autobackup/ for example) (WinSCP, wget or whatever you like..)

5: Give the script execution rights:
# chmod 770 backup.pl

5: Try
# ./backup.pl

...
backup/mysql_mysql.tgz
backup/vtigercrm503_mysql.tgz
backup/tftpboot.tgz
backup/fax.db
--12:36:44-- `/var/www/html/backup/backup-elastix-name-20090609123355-99.tar'
=> ftp://usuario:xxxxx@100.100.100.100:21/ ... 355-99.tar
Connecting to 100.100.100.100:21... connected!
Logging in as usuario ... Logged in!
Length: 455,424,000
2% [===> ] 13,370,368 229.8K/s ETA 31:18m
...


6: Programming CRONjob for automated backup once a week (in my case)
# cp backup.pl /etc/cron.weekly/
# vim /etc/crontab

45 12 * * 2 root run-parts /etc/cron.weekly

(12:45 every THU (second week-day))

7: See if everything work
# tail /var/log/
Jun 9 12:48:02 elastix crond[13906]: (root) CMD (run-parts /etc/cron.weekly)

# ls -lah /var/www/html/backup

Look at your FTP server if the file is incomming


Best regards !
 

hpwr

Joined
Jun 4, 2009
Messages
17
Likes
0
Points
0
#6
I forgotten to upload the moddified script, couldn´t edit the above post...

Also, I must comment about my problem, the script work perfect, doing the backup and uploading to my server,
but the CRONjob only do the backup, but don´t upload the file. I find it strange, why is the script not doing all the work when executing by cron.d ? Any ideas ?

Regards ! http://forum.elastix.org/old_files/backup.gz
 

mkoreen

Joined
May 21, 2009
Messages
7
Likes
0
Points
0
#7
You may have to specify full path for your wput command in the script. In general cron uses a pretty thin path, and probably won't find anything in /usr/bin or /usr/local/bin. I believe it just uses /bin:/sbin as it's path. So put in the full path of wput in the script and you should be good. For reference tar works because it's in /bin/tar.

-Marie
 

hpwr

Joined
Jun 4, 2009
Messages
17
Likes
0
Points
0
#8
Hi, I had this idea yesterday but seeing tar without path I thought it must work :S

I´ve added the full wput path and now everything work perfect !

backup.pl:
Code:
 system("/usr/local/bin/wput -t 10 $ftp_destination $backup_destination/backup-$hostname-$timestamp.tar") == 0
I´ve created a direct line in crontab for simplyfying things, without copying anything into /etc/cron.weekly/

/etc/crontab:
Code:
# Weekly Backup every Friday at 23:30
30 23 * * 5 root /root/autobackup/backup.pl
The next thing should be integrating the Scheduled backups (and upload possibility..) into the Management web from elastix, but this is up to the devs :cheer:

Thank you. http://forum.elastix.org/old_files/backup-6e5d04b60298e884910be9e91009e9f1.gz
 

izrunas

Joined
Mar 4, 2009
Messages
94
Likes
0
Points
0
#9
That's a great looking backup script. Has anyone tried anything using Dirvish (open source auto-rotating backup system? To me, the key to backups is to automate how many backups one has and to reduce the amount of bandwidth required to move them around.

Just a thought...
 

kitzul

Joined
Jul 22, 2009
Messages
2
Likes
0
Points
0
#10
I noticed when I compare the backup created using this script and the backup created inside elastix.

What is the difference between the two backups? I checked the files inside the backup and there is a difference between the two.

Thanks
-Kyle.
 

mkoreen

Joined
May 21, 2009
Messages
7
Likes
0
Points
0
#11
I don't know why they'd be different other than 2 things. The file name itself will have 99 at the end instead of the first/last letter/number of your web session. You can change that in the script. And the xml file created that has all the options for 'full backup' is just a copy of the one I got originally doing the backup from the script. You can see it as a constant inside the backup.pl file.

Try untarring both backups (assuming they are done back to back so should be the same) and then diff every file. Are they all different? are only some of them different?

-Marie
 

kitzul

Joined
Jul 22, 2009
Messages
2
Likes
0
Points
0
#12
My appologies, i was comparing an old backup vs a new backup, the backup.pl creates a backup of identical size.

I guess i jumped the gun.

Thanks for the help.
 

jcardinal

Joined
Jul 13, 2009
Messages
35
Likes
0
Points
6
#13
I have a couple questions:

Are these backups stored in the same location as those created in the web interface? If so, are they accessible for restore in the web interface? Has anyone actually tested a restore using these backups?

I don't know much about php, but couldn't you also use php from the command line to execute the exact script the web interface uses for backups? Aren't we reinventing the wheel?

Any advice is greatly appreciated. I'm just trying to stay as close to "stock" as I can. Thanks!
 

mkoreen

Joined
May 21, 2009
Messages
7
Likes
0
Points
0
#14
Yes they are stored in the same location, yes they are restorable from the web interface, and yes, I've restored from them using the web interface.

Unfortunately the only way to run the php of the actual backup script would be to send the entire thing a rather large XML POST on the command line. Good luck with that.

-Marie
 

jcardinal

Joined
Jul 13, 2009
Messages
35
Likes
0
Points
6
#15
Marie, thanks for the quick reply!

I've used a different piece of server software that offered a similar web interface for creating backups, and with that I was able to simply run "/path/to/backupScript.php 1" from the command line to generate a backup. I was hoping for a similarly simple solution here :)

Being that you're the original creator of this script, do you endorse the updates by hpwr?

hpwr, have you made any updates besides the ftp upload function and the filename format?
 

mkoreen

Joined
May 21, 2009
Messages
7
Likes
0
Points
0
#16
Hehe, if that were possible I wouldn't have written a separate script to do the same thing that it does. The problem is that the real web php backup file expects pages of POST data when it runs. While I suppose I could have reverse engineered the whole thing and created a wrapper to run it with all that data piping to it, I found it was actually simpler to just write a script that did all the same operations.

If you need something to auto-ftp the files to some other server, you're welcome to use the one hpwr made. I don't, however, have any reason to use it personally. My work's backup systems pull data via rsync, so I just made the backup dir available via rsync.
 

jcardinal

Joined
Jul 13, 2009
Messages
35
Likes
0
Points
6
#17
You couldn't have answered my question any more perfectly!

I also intend to get the backups via pull, so I'll bypass the ftp-enabled version.

Thanks!
 

hpwr

Joined
Jun 4, 2009
Messages
17
Likes
0
Points
0
#18
jcardinal said:
...
hpwr, have you made any updates besides the ftp upload function and the filename format?
No, I have not. The script is working and uploading a backup every week to the ftp server and today I restored a backup via the web interface prior uploading the file into the elastix backup directory (WinSCP, FTP, WGET etc...) location is: var www html backup

Beside the good working of this script, I´ll try some rsync solution like dirvish as suggested by
izrunas for a more complete kind of backup (we sometimes change some more internal things and the backup script don´t backup everything)

Regards !
 

jcardinal

Joined
Jul 13, 2009
Messages
35
Likes
0
Points
6
#19
Sounds like the script is working pretty well! I hope elastix decides to implement these solutions into the distribution. Manual backups only should make any admin cringe. :dry:

If you were able to put together a script that did incremental remote backups...:woohoo:
 

leiw3248

Joined
Apr 21, 2008
Messages
476
Likes
0
Points
0
#20
Hello

Our Elastix 1.6.0 used this backup.pl script to save backup to second harddisk, the second harddisk already mounted to /var/www/html/backup when installing Elastix.

The backup.pl already run in crontab: 0 1 * * * /etc/elastix_backup_script/backup.pl

The problem is I can see all backup in /var/www/html/backup from this script, but can't see in System > Backup/Restore.

How can I fix this problem?

Thanks !
 

Members online

No members online now.

Latest posts

Forum statistics

Threads
30,902
Messages
130,886
Members
17,563
Latest member
dineshr
Top