Archiving (zipping) page content folder for downloading

Trying to figure out how to archive page data (txt and images).
Thinking of using $page->contentFiles() and then create zip archive with PHP methods. But maybe there is some other way (some other $page function) how to achieve this?

This is necessary for downloading page data as backup / update to local machine.

Do you have access to your site via a shell or ftp?

1 Like

With Janitor plugin, you can create a button for creating a zip from the Panel (its a built-in job)

And in particular:

There’s also: GitHub - sylvainjule/kirby-backups: Manage backups from the Kirby panel, but I don’t know if it’s still working.

What you could also do to automate this, is create a cron job that runs at given intervals. Kirby doesn’t have methods for zipping, but you can use PHP’s ZipArchive class: PHP: ZipArchive - Manual

1 Like

I do it with the following CLI command to create zipped up backups with a bonus time stamp added on the file name so you know when the back up was made. Tweak the inclusions / stuff to skip obviously. I usually tie into an NPM script but it should also work from the cli if you have SSH access.

zip -r9 ./package/yourproject-$(date +'%d-%m-%Y-%H-%M-%S').zip public src package.json webpack.mix.js  -x '*/*.DS_Store' '*/*.lock' '*/media/*' '*/site/accounts/*' '*/site/cache/*' '*/site/sessions/*'
1 Like

I have access to site via ftp (full access), but probably I should create another account which would have access only to /content folder and only for downloading.

Currently Im writing Node JS script which (from local machine) would make request to site with Kirby and custom API would create that zip and return link to it. Which then Node JS would download and extract on local machine. Hmm, maybe connecting and downloading from ftp would be more stright forward without additional Kirby API customisation…

Absolutely. Linux, MacOS and even Windows are coming with build-in ftp clients which you can use for that simple task, even with automation in the background. You can also use curl and wget for that.

That would be a good idea too, if you are bound to a solution which uses the ftp protocol from another machine. And make sure that you ftp connection is secure.

1 Like

My Versions plugin also supports exporting the content folder as ZIP file from the Panel, with the added benefit that the content is always consistent (based on the specific version, so changes during the export process don’t affect the result). However it always exports the entire content folder, not just a particular page.

1 Like