nuxsmin / sysPass

Systems Password Manager
https://syspass.org
GNU General Public License v3.0
974 stars 207 forks source link

Backups: Setup automatic backups in the "Backup" tab #588

Open Senexis opened 7 years ago

Senexis commented 7 years ago

Please add an option to enable automatic backups every X minutes / hours / days if possible. This would make it a lot easier to manage scheduled backups.

nuxsmin commented 7 years ago

Unfortunately PHP code is parsed on runtime, so once the code is executed it's​ unloaded, so no scheduled tasks could be set.

The only way to perform it is by setting a cron job that runs an API call to backup method. There's​ a recent issue where it's explained on.

derStephan commented 7 years ago

@nuxsmin what you could do is to trigger a backup from the front-end php-script whenever

  1. the normal php-script is run AND
  2. the last backup is older than X minutes / hours / days

When we assume that changes are only done by using the front-end then there is no need to perform backups inbetween front-end calls.

Backups should then be in background to prevent delays in accessing the front-end.

Senexis commented 7 years ago

What @derStephan proposed is more than feasible. In my example, people log into the front-end frequently enough that this would cover most cases. It wouldn't apply when automatic backups are set to X minutes, but on an hourly and daily basis, this happens.

nuxsmin commented 7 years ago

@derStephan @Nadermane thanks for your points!

There is one big issue, PHP cannot (really shouldn't) create threads while running on a web server environment, so performing a backup while loading the front-end will be a blocking job.

In think that the most convenient way to perform a backup is by invoking an API call, which can be easily done through a cron job and an small PHP script (here you have an example: https://gist.github.com/nuxsmin/62338b33178544894cd7237c7fe170bd). I know that on a hosting environment it may be a hassle, but I would keep sysPass without any system related stuff because it will be a security risk. A time ago I decided to avoid using "mysqldump" for backups since it relied on a system command...

Regards

derStephan commented 7 years ago

There is one big issue, PHP cannot (really shouldn't) create threads while running on a web server environment, so performing a backup while loading the front-end will be a blocking job.

I see. But what you can do is showing a wait-animation while this is done. When I decide to enable such a backup then I will live with something like that.

In think that the most convenient way to perform a backup is by invoking an API call, which can be easily done through a cron job and an small PHP script

I completely understand your point. But not every hosted environment offers cron-jobs. And this is something which only experienced users will understand.

So why not have both? Backup for the professionals by cron and a front-end blocking backup for the casual user.

In my opinion a blocking backup is far better than no backup.

And one last point: A backup of my pretty small installation (~120 accounts) takes about 3s to be finished. I would not worry about that, even if it takes 10 times as long. And you could skip the log-table from this backup as this is not crutial for the operation.

nuxsmin commented 7 years ago

@derStephan You're right, hosted environments are pretty closed to run cron jobs, but I was thinking about how to implement that feature and from my point of view, the better way would be by adding a notice on the admin status bar, because doing it while loading the app could be dangerous since the execution time could be high on larger environments (mine is about 10000 records long -including accounts history-), and it will need to be aware of concurrency and many things like process interruption.

Due to those things I think that in-app automated backup could be a bad idea, but we could discuss (like now) a better approach to get it ;)

derStephan commented 7 years ago

doing it while loading the app could be dangerous since the execution time could be high on larger environments (mine is about 10000 records long -including accounts history-),

May I ask how long a normal backup taskes for this installation?

nuxsmin commented 7 years ago

It takes about 15 seconds, but be aware that the hardware is quite important (hosted on an IBM Xeon CPU host and EMC storage -not the fatest, but average-)

vmario89 commented 5 years ago

i think when using some cron job automatic backup could be at least be done over night ;-) better one backup per day than no current backup. I think there has to be divided into small instances where a backup every 15 minutes via cron is absolutely okay, ans some big business cases where performance counts from morning till evening. In last case some replication database will be the better backup i think. And a dump can be made from replication database in the meantime while not stressing the master.