Koozali.org: home of the SME Server

Howto backup manually?

Offline soprom

  • *
  • 589
  • +0/-0
    • www.logiciel-libre.org
Howto backup manually?
« on: April 11, 2008, 04:51:34 PM »
I have problem with getting the backup button activated.
How can I backup manually and restore on an other machine ?
Sophie from Montréal

Offline mmccarn

  • *
  • 2,656
  • +10/-0
Re: Howto backup manually?
« Reply #1 on: April 11, 2008, 05:37:35 PM »
I wrote the script below to clone my old SME onto my new hardware about a month ago.  It did *not* work flawlessly - I still needed to manually copy some information from the old system - mostly to do with odd software I have installed (smokeping, nessus)

Problems: The first time you run it, it makes a backup of the various affected directories on the new server - you can abort the clone by deleting the affected directories and renaming the copies.  However, if you run the script twice then the backup is corrupted and you can't "restore" the target server any more...

smeclone.sh:
Code: [Select]
#!/bin/bash
#smeclone.sh
#
# Clone one SME server to another using ssh / scp
#
# History:
#   2008/11/04 v.001 First draft - with bugs (backup process doesn't work right)
#
# Notes:
#   get public/private ssh authentication working before running this script
#   (in order to avoid entering the remote password over and over again...)
#
#   Included files and folders taken from http://wiki.contribs.org/Backup_server_config
#   Does not include /opt
#   Does not include /var
#
# Bugs:
#   backup of target server doesn't work right: the first run makes a backup of target files & folders, but subsequent runs destroy those backups
#
# SSHPORT is the port number on which sshd is configured on the old SME server
SSHPORT=2222

# OLDSME is the IP address of the old SME server
OLDSME=192.168.200.2

# Run the 'pre-backup' event on the old system, and the "pre-restore" event on the new one
ssh -p $SSHPORT $OLDSME '/sbin/e-smith/signal-event pre-backup'
/sbin/e-smith/signal-event pre-restore

#/etc/e-smith/templates-custom
mv /etc/e-smith/templates-custom /etc/e-smith/templates-custom.org
scp -q -p -r -P $SSHPORT $OLDSME:/etc/e-smith/templates-custom/* /etc/e-smith/templates-custom

#/etc/e-smith/templates-user-custom
mv /etc/e-smith/templates-user-custom /etc/e-smith/templates-user-custom.org
scp -q -p -r -P $SSHPORT $OLDSME:/etc/e-smith/templates-user-custom/* /etc/e-smith/templates-user-custom

#/etc/group
mv /etc/group /etc/group.org
scp -q -p -P $SSHPORT $OLDSME:/etc/group /etc/group

#/etc/gshadow
mv /etc/gshadow /etc/gshadow.org
scp -q -p -P $SSHPORT $OLDSME:/etc/gshadow /etc/gshadow

#/etc/passwd
cp -rp /etc/passwd /etc/passwd.org
scp -q -p -P $SSHPORT $OLDSME:/etc/passwd /etc/passwd

#/etc/samba/secrets.tdb
cp -rp /etc/samba/secrets.tdb /etc/samba/secrets.tdb.org
scp -q -p -P $SSHPORT $OLDSME:/etc/samba/secrets.tdb /etc/samba/secrets.tdb

#/etc/samba/smbpasswd
cp -rp /etc/samba/smbpasswd /etc/samba/smbpasswd.org
scp -q -p -P $SSHPORT $OLDSME:/etc/samba/smbpasswd /etc/samba/smbpasswd

#/etc/shadow
cp -rp /etc/shadow /etc/shadow.org
scp -q -p -P $SSHPORT $OLDSME:/etc/shadow /etc/shadow

#/etc/smbpasswd
cp -rp /etc/smbpasswd /etc/smbpasswd.org
scp -q -p -P $SSHPORT $OLDSME:/etc/smbpasswd /etc/smbpasswd

#/etc/ssh
cp -rp /etc/ssh /etc/ssh.org
scp -q -r -p -P $SSHPORT $OLDSME:/etc/ssh/* /etc/ssh

#/etc/sudoers
cp -rp /etc/sudoers /etc/sudoers.org
scp -q -p -P $SSHPORT $OLDSME:/etc/sudoers /etc/sudoers

#/home/e-smith - including users and ibays.  This one takes a long time...
 cp -rp /home/e-smith /home/e-smith.org
scp -q -p -r -P $SSHPORT $OLDSME:/home/e-smith/* /home/e-smith

#/root
cp -rp /root /root.org
scp -q-p -r -P $SSHPORT $OLDSME:/root/* /root

signal-event post-upgrade
echo '#########################################'
echo '#   You must now execute the command    #'
echo '#                                       #'
echo '#   signal-event reboot                 #'
echo '#########################################'

Offline soprom

  • *
  • 589
  • +0/-0
    • www.logiciel-libre.org
Re: Howto backup manually?
« Reply #2 on: April 11, 2008, 05:48:43 PM »
Thanks for very interesting script.
But I was thinking more about the built-in seltintra backup to usb option.
As the Selitnra Pbx backup button does not show up by itself, I'd like to do the same manually.

I guess there must be "signal-event" or the like, internal to selintra...

« Last Edit: April 11, 2008, 05:50:30 PM by soprom »
Sophie from Montréal

Offline SARK devs

  • *****
  • 2,806
  • +1/-0
    • http://sarkpbx.com
Re: Howto backup manually?
« Reply #3 on: April 11, 2008, 08:03:47 PM »
Hi sophie,

You can backup manually by dialling *901* at any phone (make sure you have the admin e-mail id set correctly because it will e-mail the backup to you.

Which device is your usbstick being associated with? (it will be /dev/sda or /dev/sdb, something like that)  You can check by doing

dmesg | grep sd

Which sail release are you running?

Best
S





Offline soprom

  • *
  • 589
  • +0/-0
    • www.logiciel-libre.org
Re: Howto backup manually?
« Reply #4 on: April 11, 2008, 08:45:41 PM »
Hi,

I'm running sail-2.2.1-603

# dmesg | grep sd
SCSI device sda: 8027793 512-byte hdwr sectors (4110 MB)
sda: Write Protect is off
sda: Mode Sense: 03 00 00 00
sda: assuming drive cache: write through
SCSI device sda: 8027793 512-byte hdwr sectors (4110 MB)
sda: Write Protect is off
sda: Mode Sense: 03 00 00 00
sda: assuming drive cache: write through
 sda: sda1
Attached scsi removable disk sda at scsi0, channel 0, id 0, lun 0

I've noticed when using the backup that it included cdr and possibly voicemail boxes. That's why I looking for more than the one in the dialplan.
Sophie from Montréal

Offline del

  • *
  • 765
  • +0/-0
Re: Howto backup manually?
« Reply #5 on: April 12, 2008, 03:37:05 AM »
This is how I just did my backup, using winscp I copied the following files from the old server:
Quote
/home/e-smith/db/selintra and /home/e-smith/db/selintra-work
to my desktop and then copied them back to the new server and all my extensions, trunks and greetings etc. were all on the new server and working OK. I hope this helps.
Del
« Last Edit: April 12, 2008, 03:41:44 AM by del »
If at first you don't succeed, then sky-diving is not for you!
"Life is like a coin. You can spend it anyway you wish, but you can only spend it once." --Author Unknown

Offline SARK devs

  • *****
  • 2,806
  • +1/-0
    • http://sarkpbx.com
Re: Howto backup manually?
« Reply #6 on: April 12, 2008, 11:50:09 AM »
It might help if I briefly explain SAIL's architecture...

SAIL has a very clean interface between the GUI and Asterisk.  It is a single Smeserver database file called selintra and it lives in /home/e-smith/db/  (where all of the smeserver control and configuration databases live).   There is a mirror image of selintra called selintra-work and up to six regresssions called selintra-undo0 thru undo5.  When you change things in the gui SAIL actually changes selintra-work.  When you do a commit, everything is moved forward, so undo4 is coipied over undo5, 3 over 4, 2 over 3 and so on up to selintra-work, which is copied over selintra,  and a generate is done.  The generate reads the database and builds the asterisk files (and all sorts of other stuff) and restarts any services that require it. 

So..  to get a backup, pretty much all you need is the selintra file.  Rebuild your smeserver environment,  copy the saved selintra file back to selintra-work and do a commit.  The only other things you might need/want are any greetings you've recorded, which can be addressed at /var/lib/asterisk/sounds/usergreeting* and your cdr records which are at /var/log/asterisk/cdr-csv/Master-csv.

With these three group of data you should be able to rebuild your SAIL PBX pretty much exactly as it was.

Hope this helps

p.s. we're enhancing the usb stick backup in -612

Best

S

Offline soprom

  • *
  • 589
  • +0/-0
    • www.logiciel-libre.org
Re: Howto backup manually?
« Reply #7 on: April 12, 2008, 09:21:28 PM »
Following different posts, I'm writing a script to backup selintra configuration to a machine ready to be used in case of problems...

There is one line I would need help with:
mv /var/lib/asterisk/sounds/usergreeting* /root/selintra/backup/greetings/
There must be a way to skip this if no file start with usergreeting

Here's my lines:
Code: [Select]
#!/bin/sh
# Send selintra configuration to an other machine
# 2008-04-12 / Sophie
# ---------------------------------------
# Needed folders:
# mkdir -p /root/selintra/backup/{db,cdr,greetings}
# will do the same as:
# mkdir /root/selintra
# mkdir /root/selintra/backup/db
# mkdir /root/selintra/backup/cdr
# mkdir /root/selintra/backup/greetings
# ---------------------------------------
# Remote access from this server to the pbx server must be prepared
# by sending keys to the remote end
# cd /root
# ssh-keygen -t rsa
# scp /root/.ssh/id_rsa.pub <SelintraHost>:/root/.ssh/authorized_keys2
#
# Daily cron at 5AM
# crontab -e
# 0 5 * * 5 /root/selintra/backup/copy_selintra_here.sh

# This server
BackupHost="192.168.0.10"

# Remote server (pbx)
SelintraHost="192.168.0.6"

# Save current selintra files (on the backup) to /root/selintra/backup in case scp fails
mv /home/e-smith/db/selintra* /root/selintra/backup/db/
mv /var/log/asterisk/cdr-csv/Master.csv /root/selintra/backup/cdr/

# this line will crash when to file found...
mv /var/lib/asterisk/sounds/usergreeting* /root/selintra/backup/greetings/

# Copy files from active PBX to backup machine
/usr/bin/scp root@$SelintraHost:/home/e-smith/db/selintra* /home/e-smith/db/
/usr/bin/scp root@$SelintraHost:/var/log/asterisk/cdr-csv/Master.csv /var/log/asterisk/cdr-csv/
/usr/bin/scp root@$SelintraHost:/var/lib/asterisk/sounds/usergreeting* /var/lib/asterisk/sounds/


Also, mysql should be included in this.
On the active pbx, there should be:
mysqldump asterisk > /root/selintra/backup/asterisk.sql

And this file should be copied to the backup machine.
« Last Edit: April 12, 2008, 09:38:38 PM by soprom »
Sophie from Montréal

Offline Teviot

  • *
  • 610
  • +0/-0
Re: Howto backup manually?
« Reply #8 on: February 19, 2009, 04:02:37 AM »

You can backup manually by dialling *901* at any phone (make sure you have the admin email id set correctly because it will email the backup to you.


S

How do we restore after doing the above backup?  Is there any documentation? 

I am about to go looking but thought I would post this first in case I didn't find any doc's
Regards
M0GLJ
......................................................
I am new to SAIL SME Server v8b6 and have been using SME for many years.
I have already done some research and only ask questions if I still can't work it out.

Offline SARK devs

  • *****
  • 2,806
  • +1/-0
    • http://sarkpbx.com
Re: Howto backup manually?
« Reply #9 on: February 19, 2009, 01:10:14 PM »
Backing SAIL up is pretty trivial.  You need to consider the following....

The sail database

/home/e-smith/db/selintra-work

it contains all of your database definitions

any user generated greetings you may have...

/var/lib/asterisk/sounds/usergreeting*

any voicemail messages you want to keep

/var/spool/asterisk/voicemail

so to copy the lot to, for example, a usbstick...

mount /media/usbdisk1
cd /media/usbdisk1
cp -a  /home/e-smith/db/selintra-work .
cp -a  /var/lib/asterisk/sounds/usergreeting* .
cp -a  /var/spool/asterisk/voicemail .

To do a restore, either to this or another machine, simply copy them back and do a commit.


Best

S

Offline lancelott2

  • *
  • 73
  • +0/-0
  • Ich bin Lancelott2
    • Meine private Homepage
Re: Howto backup manually?
« Reply #10 on: February 20, 2009, 05:19:06 AM »
Hello all,

i wrote a script to backup the basics. Its in german and only example.
You need a ibay called "backup" and a USB-Drive formatet on ext3.

Usage: ./<Scriptname>.sh <platte> <pack> <del old backup>
Bsp. ./sme-config-backup-daily.sh sda1 off off



#!/bin/bash
# Titel: SME-SERVER-KONFIGURATION - Backup-Script
# Description: Sicherung der wichtigsten Verzeichnisse des SME-Servers
# /etc /boot /opt /package /root /usr /var /home und eines MySQL-Dumpfiles
# Copyright: Thomas Bandl - www.bt-w.de
# Version 1.0

# Allgemeine Konfiguration und Angaben

#Angaben zum MySQL-Account
MYSQL_USER=YOURMYSQLUSER
MYSQL_PASS=YOURMYSQLPASSWORD

# Festlegung des Datums - Format: 20050710
DATE=`date +"%Y%m%d"`


#Angaben zur verwendeten Festplatte werden bei Aufruf
#und abgefragt
[ -z "$1" ] && echo "Error - usage: ./<Scriptname>.sh <platte> <packen> <alte Sicherung löschen>(Bsp. ./sme-config-backup-daily.sh sda1 off off)" && exit 1
platte=$1
[ -z "$2" ] && echo "Error - usage: ./<Scriptname>.sh <platte> <packen> <alte Sicherung löschen>(Bsp. ./sme-config-backup-daily.sh sda1 off off)" && exit 1
packen=$2
[ -z "$3" ] && echo "Error - usage: ./<Scriptname>.sh <platte> <packen> <alte Sicherung löschen>(Bsp. ./sme-config-backup-daily.sh sda1 off off)" && exit 1
delold=$3

sicherungsverzeichnis=backup-daily

echo "Die Sicherung erfolgt auf der Platte: " $platte
echo "Die Verzeichnisse packen: " $packen
echo "Die alte Sicherung löschen: " $delold
echo "Sicherung vom: " $DATE
echo "-------------------------------------------------"
cd /



#ALTE SICHERUNG LÖSCHEN

umount -l /dev/$platte
wait
mount /dev/$platte /home/e-smith/files/ibays/backup/html/
wait
mkdir /home/e-smith/files/ibays/backup/html/$sicherungsverzeichnis/

if [ $delold == "on" ]; then
rm -Rf /home/e-smith/files/ibays/backup/html/$sicherungsverzeichnis/*
echo "Sicherung wird erneuert!"
wait
else
echo "Sicherung wird aktualisiert!"
fi


# Das Backup-Script
#---------------------------------------------
# Hier folgt nun das eigentliche Backup-Script

#Mountpoint wechsel nach /srv
umount -l /dev/$platte
wait
mount /dev/$platte /srv
wait


#---------------VERZEICHNISSE SICHERN ANFANG

#Next wird das Verzeichnis /etc gesichert
sverzeichnis=etc
echo "Verzeichnis /" $sverzeichnis " wird gesichert!"
rsync -az --delete --delete-after /$sverzeichnis /srv/$sicherungsverzeichnis

#Next wird das Verzeichnis /boot gesichert
sverzeichnis=boot
echo "Verzeichnis /" $sverzeichnis " wird gesichert!"
rsync -az --delete --delete-after /$sverzeichnis /srv/$sicherungsverzeichnis

#Next wird das Verzeichnis /opt gesichert
sverzeichnis=opt
echo "Verzeichnis /" $sverzeichnis " wird gesichert!"
rsync -az --delete --delete-after /$sverzeichnis /srv/$sicherungsverzeichnis

#Next wird das Verzeichnis /package gesichert
sverzeichnis=package
echo "Verzeichnis /" $sverzeichnis " wird gesichert!"
rsync -az --delete --delete-after /$sverzeichnis /srv/$sicherungsverzeichnis

#Next wird das Verzeichnis /root gesichert
sverzeichnis=root
echo "Verzeichnis /" $sverzeichnis " wird gesichert!"
rsync -az --delete --delete-after /$sverzeichnis /srv/$sicherungsverzeichnis

#Next wird das Verzeichnis /usr gesichert
sverzeichnis=usr
echo "Verzeichnis /" $sverzeichnis " wird gesichert!"
rsync -az --delete --delete-after /$sverzeichnis /srv/$sicherungsverzeichnis

#Next wird das Verzeichnis /var gesichert
sverzeichnis=var
echo "Verzeichnis /" $sverzeichnis " wird gesichert!"
rsync -az --delete --delete-after /$sverzeichnis /srv/$sicherungsverzeichnis

#Next wird das Verzeichnis /home gesichert
sverzeichnis=home
echo "Verzeichnis /" $sverzeichnis " wird gesichert!"
rsync -az --delete --delete-after /$sverzeichnis /srv/$sicherungsverzeichnis


#---------------VERZEICHNISSE SICHERN ENDE


#Zurück nach Ibay Backup mounten
umount -l /dev/$platte
wait
mount /dev/$platte /home/e-smith/files/ibays/backup/html
wait

#Sicherung eines MySQL-Dumpfile
sverzeichnis=mysql-dump
echo "Verzeichnis /" $sverzeichnis " wird erstellt und gesichert!"
mkdir /home/e-smith/files/ibays/backup/html/$sicherungsverzeichnis/mysql-dump
cd /home/e-smith/files/ibays/backup/html/$sicherungsverzeichnis/mysql-dump
mysqldump -AaCceQ -u$MYSQL_USER -p$MYSQL_PASS -r mysql.dbs

cd /

#Platte UNMOUNTEN
umount -l /dev/$platte
wait

echo "Sicherung beendet!"







Restore of Databases:
--------------------------------
Copy recursive the folder to /var/lib/mysql
and change the rights recursive too to mysql.mysql


Restore Emails:
---------------------------
Backup-Path:   
cp -p /home/e-smith/files/ibays/backup/html/Maildir/cur/* /home/e-smith/Maildir/cur
cp -p /home/e-smith/files/ibays/backup/html/Maildir/new/* /home/e-smith/Maildir/new
cp -p /home/e-smith/files/ibays/backup/html/Maildir/tmp/* /home/e-smith/Maildir/tmp


Restore User-Accounts:
----------------------------------
cp -Rp /home/e-smith/files/ibays/backup/html/users/* /home/e-smith/files/users


Restore Clam-AV-Quarantine:
---------------------------------------
cp -Rp /home/e-smith/files/ibays/backup/html/var/spool/clamav/quarantine/* /var/spool/clamav/quarantine


Oh and i needed it once and it worked :). But would be also nice to see what you make out of this script.

Greetings,

lance

---------------------------------------------------------------------
Auch ich lerne noch ständig dazu!
---------------------------------------------------------------------

Offline Teviot

  • *
  • 610
  • +0/-0
Re: Howto backup manually?
« Reply #11 on: February 20, 2009, 05:50:41 AM »
Backing SAIL up is pretty trivial.  You need to consider the following....

The sail database

/home/e-smith/db/selintra-work

it contains all of your database definitions

any user generated greetings you may have...

/var/lib/asterisk/sounds/usergreeting*

any voicemail messages you want to keep

/var/spool/asterisk/voicemail

so to copy the lot to, for example, a usbstick...

mount /media/usbdisk1
cd /media/usbdisk1
cp -a  /home/e-smith/db/selintra-work .
cp -a  /var/lib/asterisk/sounds/usergreeting* .
cp -a  /var/spool/asterisk/voicemail .

To do a restore, either to this or another machine, simply copy them back and do a commit.


Best

S

Thanks S

Just a thought.

What about putting the backup and restore feature into SAIL?  I think that many people would use this feature.

Maybe even include a few different options for backup and restore

ie.  Desktop, USB, Etc

One more thing.  Will thing work with the beta version on SME8beta?
Regards
M0GLJ
......................................................
I am new to SAIL SME Server v8b6 and have been using SME for many years.
I have already done some research and only ask questions if I still can't work it out.

Offline Teviot

  • *
  • 610
  • +0/-0
Re: Howto backup manually?
« Reply #12 on: February 20, 2009, 05:52:47 AM »
Hello all,

i wrote a script to backup the basics. Its in german and only example.
You need a ibay called "backup" and a USB-Drive formatet on ext3.

Oh and i needed it once and it worked :). But would be also nice to see what you make out of this script.

Greetings,

lance

Lance

I don't think this will work with SAIL which is what the initial question was about
Regards
M0GLJ
......................................................
I am new to SAIL SME Server v8b6 and have been using SME for many years.
I have already done some research and only ask questions if I still can't work it out.

Offline lancelott2

  • *
  • 73
  • +0/-0
  • Ich bin Lancelott2
    • Meine private Homepage
Re: Howto backup manually?
« Reply #13 on: February 20, 2009, 02:24:51 PM »
oO... you are right, i havent seen that, sorry :).
---------------------------------------------------------------------
Auch ich lerne noch ständig dazu!
---------------------------------------------------------------------