Skip to content

CI4: Replace Database Backup Functionality #3451

Closed

Description

@objecttothis

Issue / Bug / Question / New Feature

CI4 no longer has the CI3 feature (https://codeigniter.com/userguide3/database/utilities.html#backup-your-database) to backup your database.

This needs to be replaced in the app\Controllers\Config.php backup_db() function. Before this can be done we need to decide on how we want to do it. @opensourcepos/org

Activity

  1. linked a pull request that will close this issueUpgrade CI to 4.1.3 (Old) #3271on Apr 1, 2022
  2. jekkos commented on Apr 5, 2022

    @jekkos
    Member

    @objecttothis I think we should just drop this as a whole. It's not something you should do from within the app. I consider it a security risk.

    Dumping a db can be done from a tool that is designed for it.

  3. jekkos commented on Apr 5, 2022

    @jekkos
    Member

    I even don't know if this feature works properly if you have a larger db, eg. Will it hit the PHP memory limit because it tries to load the whole dump in memory before sending it to the user? Personally I have never used it and always use different means to manage database backups and dumps.

  4. jekkos commented on Apr 5, 2022

    @jekkos
    Member

    If any objections please shoot @opensourcepos/org

  5. objecttothis commented on Apr 5, 2022

    @objecttothis
    MemberAuthor

    @objecttothis I think we should just drop this as a whole. It's not something you should do from within the app. I consider it a security risk.

    Dumping a db can be done from a tool that is designed for it.

    I agree. If no compelling reason to keep it, then I will drop it. The only thing I can think of is a pipe dream that I have for an unhappy install/upgrade tool. However, I would implement the db backup by calling mysqldump rather than PHP driven.

  6. chunter2 commented on Apr 6, 2022

    @chunter2
    Contributor

    @jekkos @objecttothis I actually use this functionality but really only because it was there. I have hit the PHP memory limit and will probably keep hitting it as my database grows. The nice thing about the database backup is I can access it remotely and do a backup to a different machine which saves me having to do all that manually. I'm sure there's a better way but I just haven't taken the time to figure it out.

  7. objecttothis commented on Apr 7, 2022

    @objecttothis
    MemberAuthor

    @jekkos @objecttothis I actually use this functionality but really only because it was there. I have hit the PHP memory limit and will probably keep hitting it as my database grows. The nice thing about the database backup is I can access it remotely and do a backup to a different machine which saves me having to do all that manually. I'm sure there's a better way but I just haven't taken the time to figure it out.

    @chunter2 Thanks for letting me know. It will take some initial setup, but you could setup OpenVPN to remotely VPN into your network and then install something like phpmyadmin which gives you a gui interface. Alternately SSH and use mysqldump in the CLI then FTP the backup. As I mentioned before, the current implementation doesn't work, so it would need to be redone to use something like mysqldump anyway.

  8. objecttothis commented on Apr 7, 2022

    @objecttothis
    MemberAuthor

    For reference, here is the current implementationn

    	public function backup_db(): void //TODO:https://github.com/opensourcepos/opensourcepos/issues/3451
    	{
    		$employee_id = $this->employee->get_logged_in_employee_info()->person_id;
    		if($this->employee->has_module_grant('config', $employee_id))
    		{
    			$this->load->dbutil();
    
    			$prefs = ['format' => 'zip', 'filename' => 'ospos.sql'];
    			$backup = $this->dbutil->backup($prefs);
    			$file_name = 'ospos-' . date("Y-m-d-H-i-s") . '.zip';
    
    			helper('download');
    			while(ob_get_level())
    			{
    				ob_end_clean();
    			}
    
    			force_download($file_name, $backup);
    		}
    		else
    		{
    			redirect('no_access/config');
    		}
    	}
    
  9. self-assigned this
    on Apr 7, 2022
  10. chunter2 commented on Apr 7, 2022

    @chunter2
    Contributor

    @objecttothis I actually use ssh tunnels and phpmyadmin already. Sounds like I just need to use the export function to duplicate the backup button. Thanks for the info.

  11. jekkos commented on Apr 7, 2022

    @jekkos
    Member

    I would say phpMyAdmin is the way to go here indeed.

  12. added this to the 3.4.0 milestone on Dec 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions