Kovah / LinkAce

LinkAce is a self-hosted archive to collect links of your favorite websites.
https://www.linkace.org
GNU General Public License v3.0
2.55k stars 160 forks source link

I can't backup #639

Closed welrbraga closed 1 year ago

welrbraga commented 1 year ago

Bug Description

I've follow the backup and cron instructions but without success, because "it's unable to create a directory".

How to reproduce

The enviroment is working fine for one or two weeks but just yesterday, before a update, I noted that I have read nothing about backups.

Looking for it I've found the page Backup Instruction and after read the instructions I added these lines on my ".env" file and restarted my docker compose stack.

BACKUP_ENABLED=true
BACKUP_DISK=local_backups
BACKUP_NOTIFICATION_EMAIL=welrbraga@MYMAILDOMAIN
BACKUP_MAX_SIZE=100
MAIL_DRIVER=log

The instructions were not clear about the necessity of a cron job config, so I follow this another page about Advanced Settings to generate the cron token and create file /etc/cron.d/linkace with this content:

* * * * * wbraga curl -L 'http://myhost.mydomain/cron/<my-cron-token>'

Thats is running fine, but there are nothing backed up and after almost a day with this config I caught this log message:

Level Context Date Content
error production 2023-04-14 02:02:04 Unable to create a directory at /app/storage/app/backups/linkace-backup. {"exception":"[object (League\Flysystem\UnableToCreateDirectory(code: 0): Unable to create a directory at /app/storage/app/backups/linkace-backup. at /app/vendor/league/flysystem/src/UnableToCreateDirectory.php:18)

Maybe it will be solved manually creating this folder with write permission for nginx, apache or whatever (I wil try this).

But I didn't understand why it wants to create a folder "linkace-backup" inside a folder "backup". It's is really important?

Expected behavior

I were expecting that the app creates all folders need to run correctly during installing or when it is needed used it. And in this specific case some backup files too.

Logs

error   production  2023-04-14 02:02:04 Unable to create a directory at /app/storage/app/backups/linkace-backup. {"exception":"[object] (League\\Flysystem\\UnableToCreateDirectory(code: 0): Unable to create a directory at /app/storage/app/backups/linkace-backup. at /app/vendor/league/flysystem/src/UnableToCreateDirectory.php:18)

Screenshots

No response

LinkAce version

v1.12.0

Setup Method

Docker

Operating System

Linux (Ubuntu, CentOS,...)

Client details

Server

Client

welrbraga commented 1 year ago

Like as expected, I've manually created the linkace-backup folder with "uid 82" as owner of this folder and the backup started to run fine.

On the first test I've created the folder (without adjust on ownership) but the log was clear (Unable to write = wrong permissions):

error production 2023-04-15 02:00:07 Unable to write file at location: linkace-backup/2023-04-15-02-00-06.zip. {"exception":"[object] (League\Flysystem\UnableToWriteFile(code: 0): Unable to write file at location: linkace-backup/2023-04-15-02-00-06.zip. at /app/vendor/league/flysystem/src/UnableToWriteFile.php:24)

After that, I changed the owner of folder from root to "82" (UID of www-data user inside container) and finally, my backup was concluded with a zip file saving the "/app" folder and a mysql dump.

Kovah commented 1 year ago

Thanks for taking the time to write the detailed report. The app should already have that folder writable by default by all users because this issue was reported last year. I'll take a look to check what's the issue.

Will also update the docs to include a hint for the Cron setup.

Alfablos commented 1 year ago

Hello, looking at the production Dockerfile I can guess that if you're running LinkAce under a "rootful" Docker installation this is expected: if you don't manually create the ./backup directory the Docker daemon creates it for you even before LinkAce does. As a result the directory's ownership is going to be "root:root" with a non permissive mode, which makes it inaccessible to LinkAce which, I assume, is not running as root.

I'd suggest to either adjust the configuration to put all the volumes in a ./volumes directory created before the containers start and then chmod that directory to the UID:GID LinkAce uses inside the container or (better) adding the user:"$UID:$GID" directive to the service in the compose file. You still have to create the volumes directory in advance and run chmod -R but you'll then be able to manage all the files because they'll be owned by you.

I hope this helps!