Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HOLD]✨Backup subcommand #474

Closed
wants to merge 31 commits into from

Conversation

vikaspotluri123
Copy link
Member

@vikaspotluri123 vikaspotluri123 commented Sep 12, 2017

Adds the ability to run ghost backup to create a zip archive of your important data - the config file, your content folder, and your database

ref: #468

Todo List

  • Create functions for each core task
  • Add UI logging
  • Write test suite
  • Integrate w/ extensions

@coveralls
Copy link

Coverage Status

Coverage remained the same at 72.291% when pulling 68470a9 on vikaspotluri123:backup into b5f9c44 on TryGhost:master.

I thought I did this, but apparently not 😕
@coveralls
Copy link

Coverage Status

Coverage remained the same at 72.291% when pulling f65fbfe on vikaspotluri123:backup into b5f9c44 on TryGhost:master.

Copy link
Member

@acburdine acburdine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely a good start! Just needs some fixes and tests.

The only other thing I can think of is it would probably be good to copy other things out too - e.g. the nginx and systemd config files. However, that's probably better added as an extension hook, so that the systemd and nginx extensions can do it themselves. (You don't need to implement this hook if you don't want - I can take care of it later 😁)

let exporter;
let saveLocation = process.cwd();

// @todo check if we need to ensure we're in a ghost directory

This comment was marked as abuse.


// @todo check if we need to ensure we're in a ghost directory

if (argv.output) { // @todo add o as an alias

This comment was marked as abuse.


instance.checkEnvironment();

if (instance.running()) {

This comment was marked as abuse.

this.ui.log('Ghost is currently running. Backing up might take longer and slow down your site','yellow');
}

const backupData = {

This comment was marked as abuse.


const props = {
database: exporter.doExport({}),
environment: this.system.environment

This comment was marked as abuse.

environment: this.system.environment
};

return Promise.props(props).then((data) => {

This comment was marked as abuse.

zipFile.writeZip(saveLocation);
debug('Wrote zipFile')

return Promise.resolve(saveLocation);

This comment was marked as abuse.

- No longer using the `.ghost-backup` file; that's redundant
- Use listr to log tasks
- Separate tasks into their own function
- Add support for backing up plugins (will be properly implemented in
the future)
- Add error check in backup
- Workaround adm-zip bug
Needs a LOT of modifications
@coveralls
Copy link

Coverage Status

Coverage remained the same at 77.432% when pulling 5ee8edf on vikaspotluri123:backup into 3ac283c on TryGhost:master.

Copy link
Member

@acburdine acburdine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely looking a lot better! Really just needs the directory traversing for the content folder and then tests 😄

backupContent() {
// Add content folder // @todo: Do we need to check if the content folder exists?
// @todo: Figure out how to deal with Windows bug
this.zipFile.addLocalFolder(path.join(process.cwd(), 'content/'), 'content/');

This comment was marked as abuse.

- Use fs-extra for ensureDirSync
- Meet linting requirements
- saveLocation needs to append name after all mods
-- Add instance name to save
- Add and use klaw-sync to walk content folder (Windows zip bug)
- Remove stray debugs
- Plugins are really extensions
I have a feeling the efficiency can be improved, but for now, this is
what I got!
@coveralls
Copy link

Coverage Status

Coverage remained the same at 77.432% when pulling 6200a6e on vikaspotluri123:backup into 3ac283c on TryGhost:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.8%) to 78.229% when pulling 6200a6e on vikaspotluri123:backup into 3ac283c on TryGhost:master.

Just sorted tests for easier legibility
Moved some constants to global scope
@coveralls
Copy link

Coverage Status

Coverage increased (+0.8%) to 78.229% when pulling ce92736 on vikaspotluri123:backup into 3ac283c on TryGhost:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.8%) to 78.229% when pulling 8865334 on vikaspotluri123:backup into 3ac283c on TryGhost:master.

Copy link
Member

@acburdine acburdine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely looking really good!

Just a couple of stylistic notes in the actual code; however I've got a couple of other notes that might be able to help clean up the tests.

At the moment, you're writing things in each of the tasks to this, which works and is not necessarily bad practice, but it makes it very difficult to test each task individually, which is the point of unit tests 😄

My recommendation would be in all of the functions you're currently writing something to this, e.g.this.zipFile, this.saveLocation, etc. - you instead pass a context object via listr, and write stuff to that instead. Doing so would allow you to run the individual tasks in your unit tests, instead of running all of the listr tasks at once, even though you're only testing the one task.


class BackupCommand extends Command {
run(argv) {
return this.ui.listr([{task: this.initialize.bind(this),

This comment was marked as abuse.

files = walker('./content', {nodir: true});
} catch (E) {
debug(`Failed reading content folder: ${E}`);
return Promise.reject(new Error('Failed to read content folder'));

This comment was marked as abuse.

package.json Outdated
@@ -53,6 +53,7 @@
"ghost-ignition": "2.8.14",
"inquirer": "3.2.3",
"is-running": "2.1.0",
"klaw-sync": "^3.0.0",

This comment was marked as abuse.

- Use ctx to store backup data
- For unit tests, test a single function, rather than the command each
time
- Force version for klaw
@coveralls
Copy link

Coverage Status

Coverage increased (+0.8%) to 78.229% when pulling 01458c1 on vikaspotluri123:backup into 3ac283c on TryGhost:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.9%) to 78.345% when pulling b75070d on vikaspotluri123:backup into 3ac283c on TryGhost:master.

@acburdine
Copy link
Member

This looks really good 😄 I'll pull this down and test later tonight!

@braunsonm
Copy link

Awesome! @vikaspotluri123

@coveralls
Copy link

Coverage Status

Coverage increased (+0.7%) to 82.277% when pulling f81d7e5 on vikaspotluri123:backup into 53a3425 on TryGhost:master.

@vikaspotluri123 vikaspotluri123 changed the title [WIP] ✨Backup subcommand ✨Backup subcommand Nov 10, 2017
@acburdine acburdine self-assigned this Nov 18, 2017
@acburdine
Copy link
Member

@vikaspotluri123 can you go ahead and rebase this? pulling it down and testing today but it says there are merge conflicts :/

Copy link
Member

@acburdine acburdine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it's taken so long to get to this!

Just pulled it down to test and ran into a few issues with it - which I've commented on :)

env: this.system.environment,
argv: argv,
instance: instance,
hook: this.system.hook

This comment was marked as abuse.

This comment was marked as abuse.

title: 'Writing backup file',
task: this.writeZipFile
}],{
env: this.system.environment,

This comment was marked as abuse.

}
});

return Promise.resolve();

This comment was marked as abuse.

const location = file.path.replace(/\\/g,'/');
let dir = path.dirname(location);
const name = path.basename(location);
dir = path.relative(cwd, dir);

This comment was marked as abuse.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 89.282% when pulling 3e7235b on vikaspotluri123:backup into 8a96fa1 on TryGhost:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 89.381% when pulling 534fc53 on vikaspotluri123:backup into 8a96fa1 on TryGhost:master.

@vikaspotluri123
Copy link
Member Author

👍 Done @acburdine

const read = fs.readFileSync;

return ctx.system.hook('backup').then((extensionFiles) => {
each(extensionFiles, (filesToAdd) => {

This comment was marked as abuse.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 89.387% when pulling 4ae45ff on vikaspotluri123:backup into 8a96fa1 on TryGhost:master.

@@ -52,18 +52,18 @@ module.exports = function setupEnv(typeOrDefinition, dir) {
});
}

if (setup.links) {

This comment was marked as abuse.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.6%) to 89.41% when pulling 161003e on vikaspotluri123:backup into 5ed1cfe on TryGhost:master.


if (ctx.instance.running()) {
ctx.instance.ui.log('Ghost is currently running. Backing up might take longer and slow down your site', 'yellow');
ctx.instance.loadRunningEnvironment();

This comment was marked as abuse.


backupDatabase(ctx) {
debug('Creating database backup');
let exporter;

This comment was marked as abuse.

@vikaspotluri123 vikaspotluri123 changed the title ✨Backup subcommand [HOLD]✨Backup subcommand Dec 3, 2017
folder = folder || './content';

// path MUST be relative
if (folder.indexOf('./') !== 0) {

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

@xmrcheck
Copy link

xmrcheck commented Mar 4, 2019

Hello, can we know why this feature is on hodl?
Thanks.

@acburdine
Copy link
Member

@xmrcheck apologies for the delay in getting this feature out. Given that this command is non-trivial, we will need to draft a formal spec for the command first before getting this merged in. Will try to get that done sometime soon.

@github-actions
Copy link

github-actions bot commented May 3, 2021

Our bot has automatically marked this PR as stale because there has not been any activity here in some time. If we’ve failed to review your PR & you’re still interested in working on it, please let us know. Otherwise this PR will be closed shortly, but can always be reopened later. Thank you for understanding 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants