Jump to content
kixe

Cronjob Database Backup

Recommended Posts

I've always used the all tables option but on my recent mathparser module I've used 3 fields for the same functionality:

1) radio active by default yes/no

2) if no, fields to include

3) if yes, fields to exclude

  • Like 1

Share this post


Link to post
Share on other sites
On 5/27/2016 at 7:06 AM, kixe said:

@Robin S
Thanks for pointing this out. This note is obsolete. I missed to remove it from earlier versions. The cronjob is triggered by every user.
 

Hey Kixe!
Thank you for this great module! I use it quite often.
For most projects I need the backup to get triggered when the client logout.
I don't want to give the client the backup permission, to prevent them to mess things up.
From your comment above it seems the permission is not needed.
But when I logout without the backup permission, the backup is not working.
It would be nice if the backup gets triggered by any user on logout, or at least an option for this.

  • Like 2

Share this post


Link to post
Share on other sites

Hi @kixe,

additionally to what @jploch said above, and when you are already at it ;-), it would be very helpful to have the option for auto-backup on login!

The real life usage of auto backup on logout is not consistent because some users simply leave the backend without logout process. So I would prefer to switch to auto backup on login process. :-)
(Login process can not be skipped like Logout process!)

 

  • Like 5

Share this post


Link to post
Share on other sites

@jploch @horst

Tonight a had a look in the module and I made an update to version 1.1.6

  • I removed any general permission from module. The Backup is triggered now by any user (if a time interval is set).
  • I added trigger option when a user logs in (thanks for the hint @horst).
  • I changed the name for the required permission (trigger on login or logout) from 'db-backup' to 'trigger-db-backup'. Also to prevent permission conflicts with ProcessDatabaseBackupsusing this permission.

 

  • Like 2

Share this post


Link to post
Share on other sites
13 hours ago, kixe said:

@jploch @horst

Tonight a had a look in the module and I made an update to version 1.1.6

Nice! Thanks for the quick update!
After I updated to the new version, the permission 'trigger-db-backup' wasn't available.
I created it manually and now it works. Maybe the permission wasn't created  because I updated, rather than installing a new copy? 
Anyway great update, triggering the backup on login is a nice option! 

  • Like 2

Share this post


Link to post
Share on other sites
4 hours ago, jploch said:

After I updated to the new version, the permission 'trigger-db-backup' wasn't available.
I created it manually and now it works. Maybe the permission wasn't created  because I updated, rather than installing a new copy? 

Yes, the permission will be created on install only.

  • Like 1

Share this post


Link to post
Share on other sites

Hey @kixe after upgrading from 116 to 119 I get this error:

mDyG23p.png

My workaround was uninstalling and installing it again and that worked.

Share this post


Link to post
Share on other sites

@bernhard

Thanks for pointing on this. I fixed this bug. Please update to 1.2.0

  • Like 2

Share this post


Link to post
Share on other sites

on version 1.2.0 for some reason my javascript files that are compiled with procache have the path to the js file in the beginning of the compiled file which is breaking all js on the site... This isn't happening with the earlier versions of the module....

/home/user/public_html/site/modules/CronjobDatabaseBackup/CronjobDatabaseBackup.js?v=120-1572797219;

Share this post


Link to post
Share on other sites

bump problem - still breaks all javascript on websites when using latest version, module is unusable now... sites going down...

Share this post


Link to post
Share on other sites

@kixe

So the issue here is that the module has a JS file named the same as the module - this is a problem because this module is autoload, and as such the module's JS file is polluting the front end output for any of us who use $config->scripts, meaning that our scripts for use on the front end inadvertently includes the module's js file, which is not only unnecessary, but also is breaking my frontend api.

a much better way of loading the JS file is to rename it and then just load the JS on the module's setting page, you can do that by checking the input and loading your js.

For now i just disabled the js file, i don't even know if it is needed, or being used, and this has fixed the problem.

  • Like 1

Share this post


Link to post
Share on other sites

@Macrura My two cents on this: I feel like it's the other way around — $config as a data store is (for the most part) internal to ProcessWire's backend. The $config->scripts and $config->styles arrays are wired up in a way that makes sense for the admin panel to work properly. Using them for the frontend is surely convenient (I've done that myself on a lot of sites) but probably not meant to be used that way and prone to breaking. I've personally stopped using the internal file arrays for that reason and created namespaced versions for the frontend.

  • Like 3

Share this post


Link to post
Share on other sites

@Macrura
Thanks for reporting. I fixed the issue. The JS is required only for the module settings UI. It is now only loaded there.

  • Like 1

Share this post


Link to post
Share on other sites
8 hours ago, d'Hinnisdaël said:

My two cents on this: I feel like it's the other way around — $config as a data store is (for the most part) internal to ProcessWire's backend. The $config->scripts and $config->styles arrays are wired up in a way that makes sense for the admin panel to work properly. Using them for the frontend is surely convenient (I've done that myself on a lot of sites) but probably not meant to be used that way and prone to breaking. I've personally stopped using the internal file arrays for that reason and created namespaced versions for the frontend.

In one sense that could be an interpretation, but another interpretation is that it can be used on the front end, and i know of some other devs that do use it on live sites so i think it's still risky to autoload scripts or styles on a module without just loading the assets where you need them..

Quote

Array used by ProcessWire admin to keep track of what javascript files its template should load. It will be blank otherwise. Feel free to use it for the same purpose in your own sites.

I don't currently know any modules where the $config->styles/scripts load on the front end inadvertently, but i'll keep a lookout. I have a module that loads into those for the purposes of use on the front end (Soundmanager).

The idea is to create an ecosystem where markup generating modules can have a way to load dependencies on the front end - in Soundmanager2, you need to load the various files based on your settings. By checking to see if there is anything in $config-styles/scripts, i can have modules that can load dependencies using the core $config class.

Maybe there is a better way, but $config is a useful class and i'm using it all over the place for front end development..

Share this post


Link to post
Share on other sites
1 hour ago, Macrura said:

i know of some other devs that do use it on live sites so i think it's still risky to autoload scripts or styles on a module without just loading the assets where you need them

The thing is, it's a risk that's carried by the site developer rather than the module developer. If an autoload module adds scripts and styles to $config->scripts and $config->styles it's your site that's at risk of breaking, not the module. Personally I'd never want to take that risk.

The simple solution is to create your own custom FilenameArray in $config that is reserved for front-end usage. This old post from @Soma explains how:

 

  • Like 2

Share this post


Link to post
Share on other sites

@Robin S@Macrura@d'Hinnisdaël

Interesting discussion. I suggest continuing this outside of this thread as it is not directly module-relevant. For my part, I did a useful update because the script doesn't have to be autoloaded everywhere.

Share this post


Link to post
Share on other sites

@kixe, I feel that the settings "Maximum number of backups" and "Remove backups older than" should only apply to backups created by CronjobDatabaseBackup. If the user has made manual backups, or backups have been made by a different module, then CronjobDatabaseBackup should never delete those backups. What do you think?

  • Like 3

Share this post


Link to post
Share on other sites
4 hours ago, Robin S said:

@kixe, I feel that the settings "Maximum number of backups" and "Remove backups older than" should only apply to backups created by CronjobDatabaseBackup. If the user has made manual backups, or backups have been made by a different module, then CronjobDatabaseBackup should never delete those backups. What do you think?

+1

I have automatic backups every hour during development and do manual backups when reaching milestones and they get deleted from time to time so I need to manually restore them. In my case it would be enough to exclude special filenames from deleting.

  • Like 1

Share this post


Link to post
Share on other sites
13 hours ago, Robin S said:

@kixe, I feel that the settings "Maximum number of backups" and "Remove backups older than" should only apply to backups created by CronjobDatabaseBackup. If the user has made manual backups, or backups have been made by a different module, then CronjobDatabaseBackup should never delete those backups. What do you think?

+2

All Backups from CronjobDatabaseBackup must be identified by comment signs, not by filename format. Filename formats may change for some reason.

Share this post


Link to post
Share on other sites
On 4/18/2020 at 4:37 AM, Robin S said:

@kixe, I feel that the settings "Maximum number of backups" and "Remove backups older than" should only apply to backups created by CronjobDatabaseBackup. If the user has made manual backups, or backups have been made by a different module, then CronjobDatabaseBackup should never delete those backups. What do you think?

This should have been already implemented with the option to set a custom storage path. Unfortunately I recognized a bug while looking in this. This bug is fixed now and I made some additional changements. Please update to v1.2.3.

The automated cleanup effects only the custom path and not site/assets/backups/database/ used by ProcessDatabaseBackups. Currently you cannot use ProcessDatabaseBackups to edit backups stored under a custom path.

I added functionality to protect files by 'stopword'. Files having this in its names or descriptions will be protected from beeing deleted by the cronjob. Just set the 'stopword' in the module config.

@bernhard @horst @Robin S
I hope the fix helps and feeds your needs (?)

 

  • Like 1
  • Thanks 2

Share this post


Link to post
Share on other sites

@kixe what do you think of this scenario: CronjobDatabaseBackup writes a Identifier Comment Word into all its files, and if that identifier is missing, just ignore it in all routines.?

So, stopword also sounds good, but needs manual action everytime. The other way round, if I create manual dumps and want to delegate them to CDBs cleaning routine, I can include the identifier word. This has less harm when forgot or mistake on including a word.

 

  • Like 2

Share this post


Link to post
Share on other sites

I actually ended up writing my own backup script because I wanted the backup to run by cron job at a fixed time rather than have the unpredictability inherent in LazyCron.

But in terms of this module my vote would go for having CronjobDatabaseBackup identify the backups that it creates either by filename prefix or something distinctive in the Description as per @horst's suggestion. Then the backups can be safely stored in /site/assets/backups/database/ where they can be viewed and restored via ProcessDatabaseBackups and there is no requirement to use a "file protection string" to protect backups not created by CronjobDatabaseBackup.

Share this post


Link to post
Share on other sites
On 4/21/2020 at 2:32 AM, Robin S said:

I actually ended up writing my own backup script because I wanted the backup to run by cron job at a fixed time rather than have the unpredictability inherent in LazyCron.

I use this 5 lines of code, placed in an access controlled folder under root, to run a cronjob at fixed time. Just set 'cycle' in module settings to 'none' to prevent database backups triggered by LazyCron as well.

<?php namespace ProcessWire;
$root = dirname(__DIR__);
include_once("$root/index.php");
$cdb = $modules->CronjobDatabaseBackup;
$cdb->cronBackup();

 

On 4/20/2020 at 5:04 PM, horst said:

The other way round, if I create manual dumps and want to delegate them to CDBs cleaning routine, I can include the identifier word

Thanks for the input. I thought about it. In the end, I'll leave it as it is, and the inclusion of manually created dumps in the cleaning routine remains the standard. When I manually create a dump, I usually move or download it immediately. I rarely (never?) leave it on the live server and I want the files removed automatically. The default name created by ProcessDatabaseBackups is the database name. Just use this as the 'stopword' and use a different name format in the setup of CronjobDatabaseBackup and voila it works exactly as you want it.  Furthermore there is also the option to save the files in a user-defined directory. Manually created dumps are then never affected by the CDB's cleaning routine.

  • Like 3

Share this post


Link to post
Share on other sites
On 4/18/2016 at 5:19 PM, kixe said:

Yes. The Backup is triggered by the hook function cronBackup() expecting a HookEvent as single argument, which is in fact not needed. If you want to trigger the backup from anywhere, just create a HookEvent object and call the cronBackup() function. Done.
 


$event = new HookEvent;
$modules->get('CronjobDatabaseBackup')->cronBackup($event);

Thanks for the module, it is installed on all PW sites I've ever made.
For the code snippet I still couldn't figure out how to run a database backup from an ordinary cron job.
Will I have to create a php file with the hook and call that from the cron r can I call a module file directly from cron?
Or is it possible to integrate it with the PWCron module?

Update: I got it working in a PHP file this way based on @kixe's answer:

<?php
namespace ProcessWire;

include_once("./index.php");

$event = new HookEvent();
$cron_backup = $modules->CronjobDatabaseBackup;
$cron_backup->cronBackup($event);

 

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By joshua
      This module is (yet another) way for implementing a cookie management solution.
      Of course there are several other possibilities:
      - https://processwire.com/talk/topic/22920-klaro-cookie-consent-manager/
      - https://github.com/webmanufaktur/CookieManagementBanner
      - https://github.com/johannesdachsel/cookiemonster
      - https://www.oiljs.org/
      - ... and so on ...
      In this module you can configure which kind of cookie categories you want to manage:

      You can also enable the support for respecting the Do-Not-Track (DNT) header to don't annoy users, who already decided for all their browsing experience.
      Currently there are four possible cookie groups:
      - Necessary (always enabled)
      - Statistics
      - Marketing
      - External Media
      All groups can be renamed, so feel free to use other cookie group names. I just haven't found a way to implement a "repeater like" field as configurable module field ...
      When you want to load specific scripts ( like Google Analytics, Google Maps, ...) only after the user's content to this specific category of cookies, just use the following script syntax:
      <script type="text/plain" data-type="text/javascript" data-category="statistics" data-src="/path/to/your/statistic/script.js"></script> <script type="text/plain" data-type="text/javascript" data-category="marketing" data-src="/path/to/your/mareketing/script.js"></script> <script type="text/plain" data-type="text/javascript" data-category="external_media" data-src="/path/to/your/external-media/script.js"></script> <script type="text/plain" data-type="text/javascript" data-category="marketing">console.log("Inline scripts are also working!");</script> The type has to be "optin" to get recognized by PrivacyWire, the data-attributes are giving hints, how the script shall be loaded, if the data-category is within the cookie consents of the user. These scripts are loaded asynchronously after the user made the decision.
      If you want to give the users the possibility to change their consent, you can use the following Textformatter:
      [[privacywire-choose-cookies]] It's planned to add also other Textformatters to opt-out of specific cookie groups or delete the whole consent cookie.
      You can also add a custom link to output the banner again with a link / button with following class:
      <a href="#" class="privacywire-show-options">Show Cookie Options</a> <button class="privacywire-show-options">Show Cookie Options</button> This module is still in development, but we already use it on several production websites.
      You find it here: PrivacyWire Git Repo
      Download as .zip
      I would love to hear your feedback 🙂
      CHANGELOG
      0.1.1 Debugging: fixed error during uninstall 0.1.0 Added new detection of async scripts for W3C Validation 0.0.6 CSS-Debugging for hiding unused buttons, added ProCache support for the JavaScript tag 0.0.5 Multi-language support included completely (also in TextFormatter). Added possibility to async load other assets (e.g. <img type="optin" data-category="marketing" data-src="https://via.placeholder.com/300x300">) 0.0.4 Added possibility to add an imprint link to the banner 0.0.3 Multi-language support for module config (still in development) 0.0.2 First release 0.0.1 Early development
    • By bernhard
      --- Please use RockFinder3 ---
    • By MoritzLost
      Cacheable Placeholders
      This module allows you to have pieces of dynamic content inside cached output. This aims to solve the common problem of having a mostly cacheable site, but with pieces of dynamic output here and there.  Consider this simple example, where you want to output a custom greeting to the current user:
      <h1>Good morning, <?= ucfirst($user->name) ?></h1> This snippet means you can't use the template cache (at least for logged-in users), because each user has a different name. Even if 99% of your output is static, you can only cache the pieces that you know won't include this personal greeting. A more common example would be CSRF tokens for HTML forms - those need to be unique by definition, so you can't cache the form wholesale.
      This module solves this problem by introducing cacheable placeholders - small placeholder tokens that get replaced during every request. The replacement is done inside a Page::render hook so it runs during every request, even if the response is served from the template cache. So you can use something like this:
      <h1>Good morning, {{{greeting}}}</h1> Replacement tokens are defined with a callback function that produces the appropriate output and added to the module through a simple hook:
      // site/ready.php wire()->addHookAfter('CachePlaceholders::getTokens', function (HookEvent $e) { $tokens = $e->return; $tokens['greeting'] = [ 'callback' => function (array $tokenData) { return ucfirst(wire('user')->name); } ]; $e->return = $tokens; }); Tokens can also include parameters that are parsed and passed to the callback function. There are more fully annotated examples and step-by-step instructions in the README on Github!
      Features
      A simple and fast token parser that calls the appropriate callback and runs automatically. Tokens may include multiple named or positional parameters, as well as multi-value parameters. A manual mode that allows you to replace tokens in custom pieces of cached content (useful if you're using the $cache API). Some built-in tokens for common use-cases: CSRF-Tokens, replacing values from superglobals and producing random hexadecimal strings. The token format is completely customizable, all delimiters can be changed to avoid collisions with existing tag parsers or template languages. Links
      Github Repository & documentation Module directory (pending approval) If you are interested in learning more, the README is very extensive, with more usage examples, code samples and usage instructions!
    • By Craig
      I've been using Fathom Analytics for a while now and on a growing number of sites, so thought it was about time there was a PW module for it.
      WayFathomAnalytics
      WayFathomAnalytics is a group of modules which will allow you to view your Fathom Analytics dashboard in the PW admin panel and (optionally) automatically add and configure the tracking code on front-end pages.
      Links
      GitHub Readme & documentation Download Zip Modules directory Module settings screenshot What is Fathom Analytics?
      Fathom Analytics is a simple, privacy-focused website analytics tool for bloggers and businesses.

      Stop scrolling through pages of reports and collecting gobs of personal data about your visitors, both of which you probably don't need. Fathom is a simple and private website analytics platform that lets you focus on what's important: your business.
      Privacy focused Fast-loading dashboards, all data is on a single screen Easy to get what you need, no training required Unlimited email reports Private or public dashboard sharing Cookie notices not required (it doesn't use cookies or collect personal data) Displays: top content, top referrers, top goals and more
    • By daniels
      This is a lightweight alternative to other newsletter & newsletter-subscription modules.
      You can find the Module in the Modules directory and on Github
      It can subscribe, update, unsubscribe & delete a user in a list in Mailchimp with MailChimp API 3.0. It does not provide any forms or validation, so you can feel free to use your own. To protect your users, it does not save any user data in logs or sends them to an admin.
      This module fits your needs if you...
      ...use Mailchimp as your newsletter / email-automation tool ...want to let users subscribe to your newsletter on your website ...want to use your own form, validation and messages (with or without the wire forms) ...don't want any personal user data saved in any way in your ProcessWire environment (cf. EU data regulation terms) ...like to subscribe, update, unsubscribe or delete users to/from different lists ...like the Mailchimp UI for creating / sending / reviewing email campaigns *I have only tested it with PHP 7.x so far, so use on owners risk
      EDIT:
      Since 0.0.4, instructions and changelog can be found in the README only. You can find it here  🙂
      If you have questions or like to contribute, just post a reply or create an issue or pr on github, thanks!
×
×
  • Create New...