News: This forum is now permanently frozen.
Pages: [1]
Topic: [How-To] Automatic Nightly Config Backups  (Read 3613 times)
« on: March 20, 2007, 20:46:30 »
expresscolo *
Posts: 1

Here is a bash script I wrote to do a nightly download of our m0n0wall configuration to a remote server for backup purposes. We keep a months worth and clear them out after that. Its nice to not have to worry about making a backup when you change something during the course of the day.

Here is the script:

Code:
#!/bin/bash
USER="username" # the admin username
PASS="password" # the admin password
SERVER="192.168.1.1" # the firewall's hostname or IP
PORT="6969" # the port that the admin interface listens on
METHOD="https" # set this to either http or https based on your firewall settings
DATE=`/bin/which date`
MYDATE=`$DATE "+%d-%m-%Y"`
FILENAME="nightly_m0n0wall_config-$MYDATE.xml" # the filename to save the config to (you can use full paths)
WGET=`/bin/which wget`
# You shouldn't need to touch anything below this line
if [ -f $WGET ]; then
    # Check if we are using SSL or not
    if [ $METHOD = "https" ]; then
        ADDCOMMANDS=" --no-check-certificate"
    fi

    $WGET ${METHOD}://${SERVER}:${PORT}/diag_backup.php --user=${USER} --password=${PASS} --post-data="Submit=Download configuration" -O ${FILENAME} ${ADDCOMMANDS}

fi

The code above will include the date in the filename. You can remove the DATE and MYDATE lines if you don't plan on using that, and just want to overwrite the same file night after night.

We run this nightly from a cron job as root, but any user can run it. Just make sure that the permissions of this file are correct to prevent exposing your password to other users (chmod 700).

If you have any questions, please reply to the thread and I will attempt to answer them the best I can.

This was coded with Linux in mind, but I think it should work in FBSD as well, as long as wget is installed and in the path (as well as bash, but that goes without saying). If not just change the WGET line to the full path to the wget application.
« Reply #1 on: March 21, 2007, 05:23:54 »
cmb *****
Posts: 851

There are also other options in the Handbook.

http://doc.m0n0.ch/handbook/thirdparty-automatedbackups.html
 
Pages: [1]
 
 
Powered by SMF 1.1.20 | SMF © 2013, Simple Machines