kirby-backup-widget
kirby-backup-widget copied to clipboard
Kirby panel widget to easily backup your site content.
Kirby Backup Widget
Kirby panel widget to easily backup your site content.
Installation
Use one of the alternatives below.
1. Using kirby-webpack
Simply use the built-in Kirby Package Manager by running:
$ npm run kirby:add
$ [?] Git URL: https://github.com/arnaudjuracek/kirby-backup-widget
$ [?] Module name: kirby-backup-widget
$ [?] Category: widgets
2. Kirby CLI
If you are using the Kirby CLI you can install this plugin by running the following commands in your shell:
$ cd path/to/kirby
$ kirby plugin:install arnaudjuracek/kirby-backup-widget
3. Clone or download
- Clone or download this repository.
- Unzip the archive if needed and rename the folder to
kirby-backup-widget.
Make sure that the plugin folder structure looks like this:
site/widgets/kirby-backup-widget/
4. Git Submodule
If you know your way around Git, you can download this plugin as a submodule:
$ cd path/to/kirby
$ git submodule add https://github.com/arnaudjuracek/kirby-backup-widget site/widgets/kirby-backup-widget
Options
The following options can be set in your /site/config/config.php file:
widget.backup.include
c::set('widget.backup.include', ['projects', 'blog']);
- description: array of folders to include from the backup. Note that if you use
widget.backup.exclude, all folders will be included no matter what you set inwidget.backup.include. - default: by default, all folders inside
content/are included
widget.backup.exclude
c::set('widget.backup.exclude', ['error']);
- description: array of folders to exclude from the backup. Note that if used,
widget.backup.includewill be ignored. - default:
[]
widget.backup.include_site
c::set('widget.backup.include_site', false);
- description: whether to include root files and site options. Set this to
trueif you want to backup yoursite.LANG.txtetc. - default:
false
widget.backup.destination
c::set('widget.backup.destination', 'backups');
- description: set the destination directory for the backup files. Accept subdirectory by using
'dir' . DS . 'subdir'. Note that the directory will be placed incontent/no matter what. This is mainly used to avoid collisions if you already have a directory calledbackupsincontent/. If the directory does not exist, it will be automatically created withCHMOD 0777. Finally, note that this backup directory will always be exluded, to avoid recursion. - default:
backups
widget.backup.overwrite
c::set('widget.backup.overwrite', true);
- description: set it to false if you don't want to allow backups overwrite. If set to
falseand a backup file with the same name already exists, the widget will show an alert error message. - default:
true
widget.backup.date_format
c::set('widget.backup.date_format', 'Y-m-d');
- description: set the date format used to name the backup file. See function.date.php for available formats.
- default:
Y-m-d
Security
It is recommended to limit access to your backup files by placing them behing a firewall.
Here is a quick way to prevent unauthorised user to download your backups :
config.php
c::set('routes', [
[
'pattern' => 'content/backups/(:any)',
'action' => function ($file) {
if (site()->user()) {
// only logged users have access to content/backups files
page('backups')->files()->find($file)->download();
} else {
header::forbidden();
die('Unauthorized access');
}
}
]
]);
.htaccess
# block backups from being accessed directly
RewriteRule ^content/backups/(.*)$ index.php [L]
If you want more detail about it, see how to build an asset firewall.
Todo
- [ ] change basic url
?action=parameters for a more robust widget routing solution - [ ] add confirmation modal before deleting
- [ ] swtich to .gitignore like exclude / include path patterns
Requirements
- Kirby 2.0+
Disclaimer
This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.
License
It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.