-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
Conversation
I thought I did this, but apparently not 😕
There was a problem hiding this 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 😁)
lib/commands/backup.js
Outdated
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.
This comment was marked as abuse.
Sorry, something went wrong.
lib/commands/backup.js
Outdated
|
||
// @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.
This comment was marked as abuse.
Sorry, something went wrong.
lib/commands/backup.js
Outdated
|
||
instance.checkEnvironment(); | ||
|
||
if (instance.running()) { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
lib/commands/backup.js
Outdated
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.
This comment was marked as abuse.
Sorry, something went wrong.
lib/commands/backup.js
Outdated
|
||
const props = { | ||
database: exporter.doExport({}), | ||
environment: this.system.environment |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
lib/commands/backup.js
Outdated
environment: this.system.environment | ||
}; | ||
|
||
return Promise.props(props).then((data) => { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
lib/commands/backup.js
Outdated
zipFile.writeZip(saveLocation); | ||
debug('Wrote zipFile') | ||
|
||
return Promise.resolve(saveLocation); |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
- 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
There was a problem hiding this 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 😄
lib/commands/backup.js
Outdated
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.
This comment was marked as abuse.
Sorry, something went wrong.
- 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!
Just sorted tests for easier legibility Moved some constants to global scope
There was a problem hiding this 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.
lib/commands/backup.js
Outdated
|
||
class BackupCommand extends Command { | ||
run(argv) { | ||
return this.ui.listr([{task: this.initialize.bind(this), |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
lib/commands/backup.js
Outdated
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.
This comment was marked as abuse.
Sorry, something went wrong.
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.
This comment was marked as abuse.
Sorry, something went wrong.
- Use ctx to store backup data - For unit tests, test a single function, rather than the command each time - Force version for klaw
This looks really good 😄 I'll pull this down and test later tonight! |
Awesome! @vikaspotluri123 |
@vikaspotluri123 can you go ahead and rebase this? pulling it down and testing today but it says there are merge conflicts :/ |
There was a problem hiding this 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 :)
lib/commands/backup.js
Outdated
env: this.system.environment, | ||
argv: argv, | ||
instance: instance, | ||
hook: this.system.hook |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
lib/commands/backup.js
Outdated
title: 'Writing backup file', | ||
task: this.writeZipFile | ||
}],{ | ||
env: this.system.environment, |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
lib/commands/backup.js
Outdated
} | ||
}); | ||
|
||
return Promise.resolve(); |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
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.
This comment was marked as abuse.
Sorry, something went wrong.
👍 Done @acburdine |
lib/commands/backup.js
Outdated
const read = fs.readFileSync; | ||
|
||
return ctx.system.hook('backup').then((extensionFiles) => { | ||
each(extensionFiles, (filesToAdd) => { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
test/utils/env.js
Outdated
@@ -52,18 +52,18 @@ module.exports = function setupEnv(typeOrDefinition, dir) { | |||
}); | |||
} | |||
|
|||
if (setup.links) { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
lib/commands/backup.js
Outdated
|
||
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.
This comment was marked as abuse.
Sorry, something went wrong.
|
||
backupDatabase(ctx) { | ||
debug('Creating database backup'); | ||
let exporter; |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
folder = folder || './content'; | ||
|
||
// path MUST be relative | ||
if (folder.indexOf('./') !== 0) { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Hello, can we know why this feature is on hodl? |
@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. |
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 🙂 |
Adds the ability to run
ghost backup
to create a zip archive of your important data - the config file, your content folder, and your databaseref: #468
Todo List