$this->setName('backup');
$this->setDescription('Backup a BookStack installation to a single compressed ZIP file.');
$this->addArgument('backup-path', InputArgument::OPTIONAL, 'Outfile file or directory to store the resulting backup file.', '');
- $this->addOption('no-database', null, null, "Skip adding a database dump to the backup");
- $this->addOption('no-uploads', null, null, "Skip adding uploaded files to the backup");
- $this->addOption('no-themes', null, null, "Skip adding the themes folder to the backup");
+ $this->addOption('no-database', null, InputOption::VALUE_NONE, "Skip adding a database dump to the backup");
+ $this->addOption('no-uploads', null, InputOption::VALUE_NONE, "Skip adding uploaded files to the backup");
+ $this->addOption('no-themes', null, InputOption::VALUE_NONE, "Skip adding the themes folder to the backup");
$this->addOption('app-directory', null, InputOption::VALUE_OPTIONAL, 'BookStack install directory to backup', '');
}
exec('php artisan migrate --force');
exec('php artisan bookstack:create-admin --email="' . static::$uniqueUserEmail . '" --name="Bazza" --password="hunter200"');
}
+
public function test_command_does_full_backup_of_cwd_instance_by_default()
{
chdir('/var/www/bookstack');
-
$this->assertCount(0, glob('bookstack-backup-*.zip'));
file_put_contents('/var/www/bookstack/themes/test.txt', static::$uniqueUserEmail . '-themes');
file_put_contents('/var/www/bookstack/storage/uploads/test.txt', static::$uniqueUserEmail . '-storage-uploads');
$result = $this->runCommand('backup');
- $result->dumpError();
$result->assertSuccessfulExit();
$result->assertStdoutContains("Backup finished.");
$this->assertStringContainsString(static::$uniqueUserEmail . '-public-uploads', $zip->getFromName('public/uploads/test.txt'));
$this->assertStringContainsString(static::$uniqueUserEmail . '-storage-uploads', $zip->getFromName('storage/uploads/test.txt'));
$this->assertStringContainsString(static::$uniqueUserEmail . '-themes', $zip->getFromName('themes/test.txt'));
+
+ unlink($zipFile);
}
+
+ public function test_no_options()
+ {
+ chdir('/var/www/bookstack');
+ $this->assertCount(0, glob('bookstack-backup-*.zip'));
+
+ $result = $this->runCommand('backup', [
+ '--no-database' => true,
+ '--no-uploads' => true,
+ '--no-themes' => true,
+ ]);
+ $result->assertSuccessfulExit();
+
+ $zipFile = glob('bookstack-backup-*.zip')[0];
+
+ $zip = new \ZipArchive();
+ $zip->open($zipFile);
+ $this->assertLessThan(3, $zip->numFiles);
+ $this->assertFalse($zip->getFromName('db.sql'));
+ $this->assertFalse($zip->getFromName('themes/.gitignore'));
+ $this->assertFalse($zip->getFromName('public/uploads/.gitignore'));
+ $this->assertFalse($zip->getFromName('storage/uploads/.gitignore'));
+
+ unlink($zipFile);
+ }
+
+ public function test_app_directory_option()
+ {
+ chdir('/var');
+ $this->assertCount(0, glob('bookstack-backup-*.zip'));
+
+ $result = $this->runCommand('backup', [
+ '--no-database' => true,
+ '--no-uploads' => true,
+ '--no-themes' => true,
+ '--app-directory' => '/var/www/bookstack'
+ ]);
+ $result->assertSuccessfulExit();
+
+ $zipFile = glob('bookstack-backup-*.zip')[0] ?? null;
+ $this->assertNotNull($zipFile);
+
+ unlink($zipFile);
+ }
+
+ public function test_backup_path_argument()
+ {
+ chdir('/var/www/bookstack');
+ $this->assertCount(0, glob('/home/bookstack-backup-*.zip'));
+ $this->assertFileDoesNotExist('/home/my-cool-backup.zip');
+
+ $result = $this->runCommand('backup', [
+ 'backup-path' => '/home/my-cool-backup.zip',
+ '--no-database' => true,
+ '--no-uploads' => true,
+ '--no-themes' => true,
+ ]);
+ $result->assertSuccessfulExit();
+ $this->assertFileExists('/home/my-cool-backup.zip');
+ unlink('/home/my-cool-backup.zip');
+
+ $result = $this->runCommand('backup', [
+ 'backup-path' => '/home/',
+ '--no-database' => true,
+ '--no-uploads' => true,
+ '--no-themes' => true,
+ ]);
+ $result->assertSuccessfulExit();
+ $this->assertCount(1, glob('/home/bookstack-backup-*.zip'));
+ $zipFile = glob('/home/bookstack-backup-*.zip')[0];
+ unlink($zipFile);
+ }
+
}
\ No newline at end of file