Recently I tried to use “ghost backup
” in a shell script. The idea was to use it in combination with Expect to hand over the required ghost username/email and passwords automatically. As I like the small footprint of “ghost backup” compared to a full backup of /var/www/… I though this might be a good way to go (in combination with mysqldump backups). However, I noticed the following behavior that I struggle to understand:
When starting the Expect script (details below) manually from the shell (as the ghostblog user) everything works fine and I end up with the desired backup zip-file without any further interaction. When starting the same command in a cronjob of the same user, I end up with the following error:
Debug Information:
OS: Ubuntu, v22.04.2 LTS
Node Version: v18.17.0
Ghost Version: 5.58.0
Ghost-CLI Version: 1.24.2
Environment: production
Command: 'ghost backup'
An error occurred.
Message: 'Command failed: /bin/sh -c sudo -S -p '#node-sudo-passwd#' -E -u undefined mkdir -p /var/www/mylittlesite.net/backup
sudo: unknown user undefined
sudo: error initializing audit plugin sudoers_audit
Stack: Error: Command failed: /bin/sh -c sudo -S -p '#node-sudo-passwd#' -E -u undefined mkdir -p /var/www/mylittlesite.net/backup
sudo: unknown user undefined
sudo: error initializing audit plugin sudoers_audit
at makeError (/usr/lib/node_modules/ghost-cli/node_modules/execa/index.js:174:9)
at /usr/lib/node_modules/ghost-cli/node_modules/execa/index.js:278:16
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async ensureBackupFolder (/usr/lib/node_modules/ghost-cli/lib/tasks/backup.js:17:9)
at async module.exports (/usr/lib/node_modules/ghost-cli/lib/tasks/backup.js:57:5)
at async /usr/lib/node_modules/ghost-cli/lib/commands/backup.js:35:26
Code: 1
It seems to me that starting the job via cron somehow results in an “undefined” variable that breaks the backup routine of ghost-CLI. Does anybody have an idea what the reason might be and can point me into the right direction?
Any help would be very much appreciated.
Cheers,
Alex
used Expect script <ghost_credentials.exp>:
#!/usr/bin/expect
set sudopw "mysudopassword123"
set email "admin@mylittlesite.net"
set pw "adminatmylittesitepw123"
spawn ghost backup
expect "Sudo Password"
send "$sudopw\r"
expect "Ghost administrator email address"
send "$email\r"
expect "Ghost administrator password"
send "$pw\r"
expect eof
Command to call expect script (same used for manual and crontab)
cd /var/www/mylittlesite.net && /usr/bin/expect /var/www/mylittlesite.net/ghost_credentials.exp > ~/backup.log