OPNsense
  • Home
  • Help
  • Search
  • Login
  • Register

  • OPNsense Forum »
  • Archive »
  • 16.1 Legacy Series »
  • Autobackup configuration to SCP/SFTP server.
« previous next »
  • Print
Pages: [1]

Author Topic: Autobackup configuration to SCP/SFTP server.  (Read 9194 times)

Martinezio

  • Newbie
  • *
  • Posts: 44
  • Karma: 3
    • View Profile
Autobackup configuration to SCP/SFTP server.
« on: May 16, 2016, 04:47:30 pm »
Hi :)

Is it possible to create automatic occured backup of OpnSense configuration to SCP/SFTP server?
Currently, there is only automated backup onto Google Drive, which is not best way in my opinion ;)

Solution can be triggered from OpnSense itself (even from internal crontab), but also from external server by downloading configuration XML using some fancy script ;)

Can I use for this an API key generated for special user? How?

Thx for any hint how to do this.

Best regards!
Logged

AdSchellevis

  • Administrator
  • Hero Member
  • *****
  • Posts: 855
  • Karma: 166
    • View Profile
Re: Autobackup configuration to SCP/SFTP server.
« Reply #1 on: May 16, 2016, 08:08:17 pm »
Hi Martinezio,

The easiest option in your case is probably to create your own backup script using ssh public key authentication and copy /conf/config.xml (and optional rrd files) to your remote server.

When your script is functional, you can register the backup command to configd by creating a file like this:

Code: [Select]
/usr/local/opnsense/service/conf/actions.d/actions_myactions.conf

Containing something like:
Code: [Select]
[backup]
command:/usr/local/opnsense/scripts/myscripts/backup.sh
parameters:
type:script
message:perform backup
description: perform my backup

Mind the description tag, you need it to see your command in the cron setup, which is available at:
https://192.168.1.1/ui/cron/

Then restart configd:

Code: [Select]
service configd restart

If you want to test your setup manually (using the file and tag name from this example), you can execute the following:
Code: [Select]
configctl myactions backup

Best regards,

Ad
Logged

Martinezio

  • Newbie
  • *
  • Posts: 44
  • Karma: 3
    • View Profile
Re: Autobackup configuration to SCP/SFTP server.
« Reply #2 on: May 17, 2016, 11:14:00 am »
Wow, thx for this :)

I will test it and leave a note if it works for me :)

Best regards.
Logged

Martinezio

  • Newbie
  • *
  • Posts: 44
  • Karma: 3
    • View Profile
Re: Autobackup configuration to SCP/SFTP server.
« Reply #3 on: May 17, 2016, 01:03:31 pm »
Ok, my script itself works perfectly, but I can't do the cron magic. I don't have such url: 192.168.x.x/ui/cron available - when I enter this manualy, I land on system status page.
I've used a standard shell to access crontab and will see if it works.

Thx for Your help :) Case is solved.
Logged

AdSchellevis

  • Administrator
  • Hero Member
  • *****
  • Posts: 855
  • Karma: 166
    • View Profile
Re: Autobackup configuration to SCP/SFTP server.
« Reply #4 on: May 17, 2016, 02:14:26 pm »
I guess you miss a / at the end of the url when you enter https://192.168.1.1/ui/cron it routes back to the dashboard.  this https://192.168.1.1/ui/cron/  should route to the cron setup page.
Logged

franco

  • Administrator
  • Hero Member
  • *****
  • Posts: 13949
  • Karma: 1208
    • View Profile
Re: Autobackup configuration to SCP/SFTP server.
« Reply #5 on: May 17, 2016, 02:21:23 pm »
Cron Page should be opened for general access in 16.7. Currently doing a bit more refactoring to make it more centralised as there was an old Cron system in place too.
Logged

Martinezio

  • Newbie
  • *
  • Posts: 44
  • Karma: 3
    • View Profile
Re: Autobackup configuration to SCP/SFTP server.
« Reply #6 on: May 17, 2016, 02:40:26 pm »
Indeed I've ommited trailing slash. Now I can see my script in cron and have tested it working from cron :) Thanks a lot!

BTW: why it is not supported settings cron action every n amount of time? In linux we can write like this:
Code: [Select]
*/5 * * * * somefancyscript.sh
and it will run every 5 min...
Ok, You're working on refactoring cron implementation, but will this be supported in new implementation? :)
Logged

franco

  • Administrator
  • Hero Member
  • *****
  • Posts: 13949
  • Karma: 1208
    • View Profile
Re: Autobackup configuration to SCP/SFTP server.
« Reply #7 on: May 17, 2016, 03:26:52 pm »
Right, it's supported by FreeBSD so I filed a GUI bug:

https://github.com/opnsense/core/issues/946
Logged

  • Print
Pages: [1]
« previous next »
  • OPNsense Forum »
  • Archive »
  • 16.1 Legacy Series »
  • Autobackup configuration to SCP/SFTP server.
 

OPNsense is an OSS project © Deciso B.V. 2015 - 2023 All rights reserved
  • SMF 2.0.19 | SMF © 2021, Simple Machines
    Privacy Policy
    | XHTML | RSS | WAP2