CLI backup & restore tool/script

[thanks to some good folks in the IRC channel for their guidance]

I’m migrating my current PBX from a VM to a RasPi.
I have a relatively stable setup atm on my old host, and I’d like to port this stable setup to my new RasPi “toy”.

I’ve made use of the Backup & Retore module to schedule daily config backups, but I’m having difficulty importing the current config into the new host through the same mechanism - either a bug in my browser, gui or module on new system, or the backed-up data is corrupt (little or no sensible output, so it’s hard to say)

What I would suggest/request is a CLI script/tool to complement the GUI one, so that a config snapshot of all relevant config data, SQL & config files, so that a CLI-verbose backup & restoration can be done & nothing will fall through the cracks.

For now I’ll attempt to dump & import the MySQL DB

I’ve done this a bunch of times and here’s what works for me:

Backup databases (have your DB password ready)

mysqldump --opt -u asteriskuser -p asterisk > asterisk.mysql.db
mysqldump --opt -u asteriskuser -p asteriskcdrdb > asterisk.mysqlcdrdb.db

archive the most important directories (note this command is on one line):

 find /etc/amportal.conf /etc/freepbx.conf /etc/dahdi /etc/wanpipe /etc/asterisk /var/lib/asterisk/astdb /var/www/html/pbxAdmin /var/spool/asterisk/voicemail /var/lib/asterisk/sounds/custom /var/spool/hylafax/etc /var/spool/hylafax/bin  asterisk.myslq.db asteriskcdrdb.myslq.db  -depth | afio -ovZ asterisk-backup.afio.gz

Install asterisk binaries, etc on the target machine, then the database and archived files. Reinstall FreePBX from the tar ball (./install_amp), run updates, etc.

You need to double check the files / directories to be sure they match your installation but otherwise this method has worked well for me.

Area51, this process misses the AstDB. You also need to spool off that. You can do a “database show” in Asterisk and the write a script to “put” it all back.

You mean /var/lib/asterisk/astdb? It’s in the list as I’ve missed it before :smiley:

Thank you for that information - it’ll come in very handy.
I’l start building a script to automate this needed process

Cool guys, there already is a script in /var/lib/asterisk/bin/dumpastdb.php that does what you want.

Nice. I’ve always simply copied it from machine to machine with no known ill effect.

I see there is a restore script too. /var/lib/asterisk/bin/restoreastdb.php