Skip to content
This repository has been archived by the owner on Jul 4, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/1.0.0' into 'master'
Browse files Browse the repository at this point in the history
Release/1.0.0

See merge request open-source/dokuwiki/backup!42
  • Loading branch information
tatewake committed Sep 14, 2020
2 parents 0ab86b6 + a6e8516 commit 8fad6f0
Show file tree
Hide file tree
Showing 24 changed files with 555 additions and 203 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.php_cs.cache
38 changes: 38 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
### Changed
### Removed
### Fixed

## [1.0.0] - 2020-09-14

### Added

- [BT-38] - When creating a backup file, we now ensure we don't backup any metadata about backups, and we also delete any "already deleted" backups in the `media_attic` that the user cannot otherwise delete
- [BT-44] - Added this CHANGELOG.md file and first official version number 1.0.0 and release date to 2020-09-14
- [BT-46] - Added LICENSE, rewrote README.md and some re-writing of how the backup page looks

### Changed

- [BT-39] - When the backup completes, we now hide the "backup progress" text
- [BT-42] - If a user is running on a Windows-based server, we now alert the user that there may be issues with the plugin, and force an "I Understand" button to be pressed to show the plugin
- [BT-43] - Did some code cleanup via `php-cs-fixer` and `js-beautify`; also removed German, French, and Japanese translations as they're now out of date and need to be redone

##

[1.0.0]: https://github.com/tatewake/dokuwiki-plugin-backup/releases/tag/1.0.0

[BT-39]: https://github.com/tatewake/dokuwiki-plugin-backup/issues/39
[BT-38]: https://github.com/tatewake/dokuwiki-plugin-backup/issues/38

[BT-42]: http://192.168.1.150/open-source/dokuwiki/backup/-/issues/42
[BT-43]: http://192.168.1.150/open-source/dokuwiki/backup/-/issues/43
[BT-44]: http://192.168.1.150/open-source/dokuwiki/backup/-/issues/44
[BT-46]: http://192.168.1.150/open-source/dokuwiki/backup/-/issues/46
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

29 changes: 0 additions & 29 deletions README

This file was deleted.

43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# BackupTool for DokuWiki

## License

* **Author**: [Terence J. Grant](mailto:tjgrant@tatewake.com) (with special thanks to [Andreas Wagner](andreas.wagner@em.uni-frankfurt.de) and [Andreas Gohr](dokuwiki@cosmocode.de))
* **License**: [GNU GPL v2](http://opensource.org/licenses/GPL-2.0)
* **Latest Release**: v1.0.0 on Sep 14th, 2020
* **Changes**: See [CHANGELOG.md](CHANGELOG.md) for full details.
* **Donate**: [Donations](http://tjgrant.com/wiki/donate) and [Sponsorships](https://github.com/sponsors/tatewake) are appreciated!

## About

This tool allows you to easily create backups of your [DokuWiki](http://dokuwiki.org/) data and other configuration / settings from the admin interface.

The tool will create a [tar](https://en.wikipedia.org/wiki/Tar_(computing)) archive, and optionally compressed with either [bzip2](https://en.wikipedia.org/wiki/Bzip2) or [gzip](https://en.wikipedia.org/wiki/Gzip) if either of these compression methods are available.

## Install / Upgrade

Search and install the plugin using the [Extension Manager](https://www.dokuwiki.org/plugin:extension). Refer to [Plugins](https://www.dokuwiki.org/plugins) on how to install plugins manually.

You can then run backups manually from the **Backup Tool** link in the **Additional Plugins** section of your DokuWiki installation's **Admin** page.

Backup archives will be available via the **Media Manager** at the path `:wiki:backup`.

## Setup

All further documentation for this plugin can be found at:

* [https://www.dokuwiki.org/plugin:backup](https://www.dokuwiki.org/plugin:backup)

## Contributing

The official repository for this plugin is available on GitHub:

* [https://github.com/tatewake/dokuwiki-plugin-backup](https://github.com/tatewake/dokuwiki-plugin-backup)

The plugin thrives from community contributions. If you're able to provide useful code changes or bug fixes, they will likely be accepted to future versions of the plugin.

If you find my work helpful and would like to give back, [consider joining me as a GitHub sponsor](https://github.com/sponsors/tatewake).

Thanks!

--Terence
119 changes: 103 additions & 16 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ class admin_plugin_backup extends DokuWiki_Admin_Plugin
protected $prefFile = DOKU_CONF . 'backup.json';
protected $filters = null;

protected function isRunningWindows()
{
return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? true : false;
}

public function btRemoveFiles($dir, $startString)
{
if (is_dir($dir)) {
$objects = scandir($dir);

foreach ($objects as $object) {
if ($object != "." && $object != ".." && substr($object, 0, strlen($startString)) === $startString) {
if (!is_dir($dir. DIRECTORY_SEPARATOR .$object) || is_link($dir."/".$object)) {
unlink($dir. DIRECTORY_SEPARATOR .$object);
}
}
}
}
}

/** @inheritdoc */
public function handle()
{
Expand All @@ -34,14 +54,36 @@ public function html()
echo '<div class="plugin_backup">';

if ($INPUT->post->bool('backup')) {
$this->removeMediaAtticBackups();
$this->runBackup();
} else {
echo '<h1>' . $this->getLang('menu') . '</h1>';

if ($this->isRunningWindows()) {
msg($this->getLang('windows-msg'), 2);
}

if ($this->isRunningWindows()) {
echo '<div class="bt-warning" style="display: block;">';
echo $this->locale_xhtml('windows');
echo '<button type="button" class="collapsible">I understand</button>';
echo '</div>';

echo '<div class="bt-content" style="display: none;">';
} else {
echo '<div>';
}

echo $this->locale_xhtml('intro');

echo $this->getForm();

$this->listBackups();

echo $this->locale_xhtml('donate');
echo '</div>';
}

echo $this->locale_xhtml('donate');
echo '</div>';
}

Expand Down Expand Up @@ -79,13 +121,26 @@ protected function listBackups()
echo '</div>';
}

protected function removeMediaAtticBackups()
{
try {
global $conf;

$self = fullpath(dirname(mediaFN($this->getConf('backupnamespace') . ':foo')));
$targetdir = $conf['mediaolddir'] . '/' . $this->stripPrefix($self, fullpath(dirname(mediaFN($conf['savedir']))));

$this->btRemoveFiles($targetdir, 'dw-backup-');
} catch (Exception $e) {
}
}

/**
* Runs the backup process with XHTML output
*/
protected function runBackup()
{
echo '<h1>' . $this->getLang('menu') . '</h1>';
echo '<p class="running">';
echo '<p class="bt-running">';
echo hsc($this->getLang('running'));
echo '&nbsp;';
echo '<img src="' . DOKU_BASE . 'lib/plugins/backup/spinner.gif" alt="…" />';
Expand All @@ -95,7 +150,6 @@ protected function runBackup()
$fn = mediaFN($id);
try {
echo '<div class="log">';
echo '<script>plugin_backup.start();</script>';
tpl_flush();
$this->createBackup($fn, $this->loadPreferences(), [$this, 'logXHTML']);
echo '</div>';
Expand All @@ -105,8 +159,8 @@ protected function runBackup()
msg('Backup failed. ' . $e->getMessage(), -1);
@unlink($fn);
}

echo '<script>plugin_backup.stop();</script>';
echo '<script>document.getElementsByClassName(\'bt-running\')[0].style.display=\'none\';</script>';
}

/**
Expand Down Expand Up @@ -145,11 +199,15 @@ protected function getForm()
$prefs = $this->loadPreferences();
foreach ($prefs as $pref => $val) {
$label = $this->getLang('bt_' . $pref);
if (!$label) continue; // unknown pref, skip it
if (!$label) {
continue;
} // unknown pref, skip it

$form->setHiddenField("pref[$pref]", '0');
$cb = $form->addCheckbox("pref[$pref]", $label)->useInput(false)->addClass('block');
if ($val) $cb->attr('checked', 'checked');
if ($val) {
$cb->attr('checked', 'checked');
}
}

$form->addButton('backup', $this->getLang('bt_create_backup'));
Expand Down Expand Up @@ -226,7 +284,9 @@ protected function createBackup($fn, $prefs, $logger)
$tar->create($fn);

foreach ($prefs as $pref => $val) {
if (!$val) continue;
if (!$val) {
continue;
}

$cmd = [$this, 'backup' . ucfirst($pref)];
if (is_callable($cmd)) {
Expand Down Expand Up @@ -261,10 +321,16 @@ protected function addDirectoryToTar(Tar $tar, $dir, $as, $logger = null, $filte
$file = $as . '/' . $file;

// custom filter:
if ($filter !== null && !$filter($file)) continue;
if (!$this->defaultFilter($file)) continue;
if ($filter !== null && !$filter($file)) {
continue;
}
if (!$this->defaultFilter($file)) {
continue;
}

if ($logger !== null) $logger($file);
if ($logger !== null) {
$logger($file);
}
$tar->addFile($path, $file);
}
}
Expand All @@ -285,10 +351,14 @@ protected function defaultFilter($path)
$this->filters = array_filter($this->filters);
}

if (strpos($path, '/.git') !== false) return false;
if (strpos($path, '/.git') !== false) {
return false;
}

foreach ($this->filters as $filter) {
if (strpos($path, $filter) === 0) return false;
if (strpos($path, $filter) === 0) {
return false;
}
}

return true;
Expand Down Expand Up @@ -406,7 +476,16 @@ protected function backupMedia(Tar $tar, $logger)
protected function backupMediarevs(Tar $tar, $logger)
{
global $conf;
$this->addDirectoryToTar($tar, $conf['mediaolddir'], 'data/media_attic', $logger);

// figure out what our backup folder would be called within the backup
$media = fullpath(dirname(mediaFN('foo')));
$self = fullpath(dirname(mediaFN($this->getConf('backupnamespace') . ':foo')));
$relself = 'data/media_attic/' . $this->stripPrefix($self, $media);

$this->addDirectoryToTar($tar, $conf['mediaolddir'], 'data/media_attic', $logger, function ($path) use ($relself) {
// skip our own backups
return (strpos($path, $relself) !== 0);
});
}

/**
Expand All @@ -420,7 +499,16 @@ protected function backupMediarevs(Tar $tar, $logger)
protected function backupMediameta(Tar $tar, $logger)
{
global $conf;
$this->addDirectoryToTar($tar, $conf['mediametadir'], 'data/media_meta', $logger);

// figure out what our backup folder would be called within the backup
$media = fullpath(dirname(mediaFN('foo')));
$self = fullpath(dirname(mediaFN($this->getConf('backupnamespace') . ':foo')));
$relself = 'data/media_meta/' . $this->stripPrefix($self, $media);

$this->addDirectoryToTar($tar, $conf['mediametadir'], 'data/media_meta', $logger, function ($path) use ($relself) {
// skip our own backups
return (strpos($path, $relself) !== 0);
});
}

/**
Expand Down Expand Up @@ -452,5 +540,4 @@ protected function backupPlugins(Tar $tar, $logger)
}

// endregion

}
15 changes: 0 additions & 15 deletions deleted.files

This file was deleted.

1 change: 0 additions & 1 deletion lang/de/donate.txt

This file was deleted.

16 changes: 0 additions & 16 deletions lang/de/intro.txt

This file was deleted.

20 changes: 0 additions & 20 deletions lang/de/lang.php

This file was deleted.

4 changes: 0 additions & 4 deletions lang/de/settings.php

This file was deleted.

Loading

0 comments on commit 8fad6f0

Please sign in to comment.