Skip to content

Conversation

@beposec
Copy link
Contributor

@beposec beposec commented Mar 17, 2025

The goal of this feature is to store backups on an SFTP server that automatically relocates the backup files to a non-accessible folder after they are created. Additionally, it should support storing backups from multiple firewalls.
Identified Issues:

  1. OPNsense displays an error after creating the backup because the file is relocated, making it inaccessible.
  2. All OPNsense backups are saved with the same filename which makes it hard to identify the files.

Enhancements Introduced in This Pull Request:

  1. Hostname Prefix: Backup files can now optionally be prefixed with the hostname, similar to the Google Drive backup feature.
  2. Disable Housekeeping: Setting 'Backup Count' to 0 disables housekeeping, allowing backups to be stored on an SFTP server that moves files to a different folder.

Copy link
Member

@AdSchellevis AdSchellevis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beposec I left some small remarks, but generally it looks good, thanks

$config = $cnf->object();
if ($this->model->prefixhostname->isEmpty()) {
$fileprefix = "config-";
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better move $config = Config::getInstance()->object(); inside the block

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved $config to the else block.

}
return $remote_backups;
} else {
return array($target_filename);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return array($target_filename);
return $this->ls(sprintf('%s*.xml', $fileprefix));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Listing the file here is not possible because it is moved to another directory immediately after creation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's pretty inconsistent with the block above, which starts with querying the the other end to know if it should actually do a backup. If we always want an unconditional push, it might be better to flag this as a separate option with appropriate code path.

I do expect that returning an empty list doesn't cause any real issues by the way, which is technically also the correct answer, after the backup, we can't know the actual result as the file has been moved. In which case just returning the remote list should be good enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are absolutely right. I have adapted it so that it lists the existing files consistently like the other blocks, but if there are no files, it simply tells you so.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, but why not just let it return [] ? just checking in case I'm missing something here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it. When it returns [] the backup is executed, but throws an error. I think this is the reason:

https://github.com/opnsense/core/blob/master/src/www/diag_backup.php#L401C1-L401C50

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the actual backup doesn't look at the result, but the admin page is, I'll take a look, thanks

@beposec beposec requested a review from AdSchellevis March 17, 2025 20:34
AdSchellevis added a commit to opnsense/core that referenced this pull request Mar 19, 2025
AdSchellevis added a commit to opnsense/core that referenced this pull request Mar 19, 2025
@AdSchellevis AdSchellevis merged commit 2a77f7d into opnsense:master Mar 19, 2025
AdSchellevis added a commit that referenced this pull request Mar 19, 2025
…ver (#4602)

* Add possibility for hostname prefix for backups and allow usage of filedrop only sftp server

* Move config variable into else block

* Set value in case no backups where found on the server and housekeeping is disabled.

---------

Co-authored-by: Ad Schellevis <AdSchellevis@users.noreply.github.com>
@AdSchellevis
Copy link
Member

@beposec this 037cb53 combined with opnsense/core@c48d393 should do the trick.

@beposec
Copy link
Contributor Author

beposec commented Mar 19, 2025

I will verify that soon, but it should work. Thanks for the quick and productive implementation process. Can't wait to implement it in production ☺️

fichtner pushed a commit to opnsense/core that referenced this pull request Mar 20, 2025
@beposec
Copy link
Contributor Author

beposec commented Mar 28, 2025

Do you have any idea when this will go into production?

@AdSchellevis
Copy link
Member

probably next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants