Web based family history software

Question Autobackup data base and dedcom file and restore - module

  • webtreesFUN
  • Topic Author
  • Offline
  • New Member
  • New Member
More
10 months 1 week ago #1 by webtreesFUN
What You think guys about this type solution?
Code:
<?php // Required webtrees library files require_once 'includes/session.php'; require_once 'includes/functions/functions_db.php'; class BackupPlugin extends Plugin {          public function __construct() {         parent::__construct();         $this->owner = 'webtrees';         $this->path = WT_PLUGIN_DIR . '/backup_plugin/';         $this->name = 'Backup Plugin';         $this->version = '1.0';     }     public function init() {         // Register hook to be called at specific moments         PluginService::getInstance()->registerHook($this, 'userAccountMaintenance', 'backupDatabase');         PluginService::getInstance()->registerHook($this, 'form', 'backupForm');         PluginService::getInstance()->registerHook($this, 'processForm', 'processBackupForm');     }     public function backupDatabase() {         // Check if it's time for scheduled backup         $scheduled_backup_time = // Retrieve scheduled backup time from database         $current_time = time();         if ($current_time >= $scheduled_backup_time) {             // Backup database             $backup_dir = WT_DATA_DIR . '/backups/';             $backup_filename = 'database_backup_' . date('Y-m-d_H-i-s') . '.sql';             $backup_path = $backup_dir . $backup_filename;             exec("mysqldump -u" . DB_USER . " -p" . DB_PASS . " " . DB_NAME . " > $backup_path");             // Backup GEDCOM file             $gedcom_file = WT_DATA_DIR . '/data.ged';             $gedcom_backup_dir = WT_DATA_DIR . '/gedcom_backups/';             $gedcom_backup_filename = 'gedcom_backup_' . date('Y-m-d_H-i-s') . '.ged';             $gedcom_backup_path = $gedcom_backup_dir . $gedcom_backup_filename;             copy($gedcom_file, $gedcom_backup_path);             // Update scheduled backup time in database             // Update scheduled_backup_time in database with new scheduled time             $this->logMessage("Scheduled database backup created: $backup_filename", 'INFO');             $this->logMessage("Scheduled GEDCOM backup created: $gedcom_backup_filename", 'INFO');         }     }     public function backupForm($args) {         // Add form for manual backup initiation         if ($args['type'] == 'administration') {             echo '<form action="' . WT_WEB_URL . '/backend.php" method="post">';             echo '<input type="hidden" name="page" value="backup">';             echo '<input type="hidden" name="action" value="backup">';             echo '<input type="submit" value="Backup Now">';             echo '</form>';         }     }     public function processBackupForm($args) {         // Process manual backup form submission         if ($args['page'] == 'backup' && $args['action'] == 'backup') {             // Backup database             $backup_dir = WT_DATA_DIR . '/backups/';             $backup_filename = 'database_backup_' . date('Y-m-d_H-i-s') . '.sql';             $backup_path = $backup_dir . $backup_filename;             exec("mysqldump -u" . DB_USER . " -p" . DB_PASS . " " . DB_NAME . " > $backup_path");             // Backup GEDCOM file             $gedcom_file = WT_DATA_DIR . '/data.ged';             $gedcom_backup_dir = WT_DATA_DIR . '/gedcom_backups/';             $gedcom_backup_filename = 'gedcom_backup_' . date('Y-m-d_H-i-s') . '.ged';             $gedcom_backup_path = $gedcom_backup_dir . $gedcom_backup_filename;             copy($gedcom_file, $gedcom_backup_path);             // Provide feedback to user             echo 'Backup completed successfully.';         }     }     public function restoreBackup($backup_filename) {         // Restore database and GEDCOM from backup files         // Implement restoration logic here     } } // Register the plugin $backup_plugin = new BackupPlugin(); PluginService::getInstance()->registerPlugin($backup_plugin);

After many mistakes and errors around webtress management for relations I see need to manage backups to fix some data.

Please Log in or Create an account to join the conversation.

  • hermann
  • Away
  • Elite Member
  • Elite Member
More
10 months 1 week ago #2 by hermann
It would be helpful if you could describe: what is the problem and what is the idea behind your solution.

Some remarks: webtrees supports several types of databases, not only MySQL. Many users have more than one tree, so they should be saved all together (as it was done when you upgrade webtrees).

There was a similar solution some years ago by JustCarmen (supporting webtrees 1.x only).

Hermann
Designer of the custom module "Extended Family"

webtrees 2.1.21 (all custom modules installed, PHP 8.3.12, MariaDB 10.6) @ ahnen.hartenthaler.eu

Please Log in or Create an account to join the conversation.

  • webtreesFUN
  • Topic Author
  • Offline
  • New Member
  • New Member
More
10 months 1 week ago #3 by webtreesFUN
Maybe You know the PHPbb solution around backups?
It's done in panel (Backup and Restore last or selected version). Admins doing quick snapshot as backup before some changes, especially if addon doing modifications on data base.

Did not know about JustCarmen solution
github.com/JustCarmen/fancy_database_backup
I see.. well it should be restored : ) ..upgraded I think.

Please Log in or Create an account to join the conversation.

  • JustCarmen
  • Away
  • Elite Member
  • Elite Member
More
10 months 1 week ago #4 by JustCarmen

Did not know about JustCarmen solution
github.com/JustCarmen/fancy_database_backup
I see.. well it should be restored : ) ..upgraded I think.

I'm sorry, but I have no plans to upgrade the module. The module used an external library that is no longer maintained, so I have decided to discontinue the module. 

Personally, I no longer need this backup solution. My host backs up the website and database every night and if something goes wrong, I can restore my site at the touch of a button.


Carmen
Designer of the JustLight theme (comes with a light and dark color palette), Fancy Imagebar, Fancy Research Links and Fancy Treeview for webtrees 2


Check my website at www.justcarmen.nl

Please Log in or Create an account to join the conversation.

  • webtreesFUN
  • Topic Author
  • Offline
  • New Member
  • New Member
More
10 months 1 week ago #5 by webtreesFUN
Gotch your point around. Also have backups, but are 1 per day around 3:00 AM and if users doing something by whole days can lose data.

Maybe check this:
www.phpbb.com/support/docs/en/3.2/ug/adm...aintenance_database/

This solution exist years and is very helpful as I manage this type system.

Please Log in or Create an account to join the conversation.

More
10 months 1 week ago #6 by fisharebest
> Gotch your point around. Also have backups, but are 1 per day around 3:00 AM and if users doing something by whole days can lose data.

If you are using MySQL, you can enable transaction/replication logs. This way, you can restore from.a backup, and then replay the transactions up to the exact time the error occured.

You can even exclude the error SQL statements, and the recover all the subsequent trandactions.

This is what I use on my server. I have daily/weekly/monthly backups and transaction logs. I can restore my database to any time in the last 4 months.

Greg Roach - greg@subaqua.co.uk - @fisharebest@phpc.social - fisharebest.webtrees.net

Please Log in or Create an account to join the conversation.

Powered by Kunena Forum