coollabsio / coolify

An open-source & self-hostable Heroku / Netlify / Vercel alternative.
https://coolify.io
Apache License 2.0
27.32k stars 1.41k forks source link

[Feature]: Backup Manger in the UI #2389

Open ayntk-ai opened 1 month ago

ayntk-ai commented 1 month ago

General Idea

Currently only databases are backed up. Also, only some databases have a restore option. See: https://github.com/coollabsio/coolify/issues/2501. Streamline database backups and offer a one click restore option without having to manually download and upload the backup. Also there should be a second checkbox that allows us to set container backups -> a container backup is just a backup of all the persistent data (volumes) of the container.

Detailed Description

I think it should be pretty straightforward for the pro @andrasbacsai. I thought about all the points and how I would implement it below, hope it helps (can not implement it myself for now as I am not experienced enough with Larvel):

delete old Backups with find

ssh "${remote_target}" "find ${remote_dir} -type f -name '*-backup.tar.gz' -mtime +$keep_backups -exec rm {} \;"

- [ ] 9. set what to backup -> only database, only files or everything --> everything means full container, database and all configurations set in ccolify
Database already works
Files would essentially be every volume of the docker container, since all other docker data is not persistent.
Both would just let us schedule a cron job to do both.
-> As all services run in containers (even in the future when k8s is supported) there is essentially just the need to backup all volumes in the folder (but it is better to let us select backups on a container level/ service level -> just backup the WordPress volumes): 
```bash
/var/lib/docker/volumes

-> At the Coolify level, we can select Backup All --> and with Backup All, it basically just backs up all the volumes in the Docker volumes directory.

Manual script as a demo (source: https://schroederdennis.de/docker/docker-volume-backup-script-sichern-mit-secure-copy-scp-nas/)

#!/bin/bash
# # # # # # # # # # # # # # # # # # # # # # # #
#                Configuration                #
# # # # # # # # # # # # # # # # # # # # # # # #

# Directory to be backed up
source_dir="/var/lib/docker/volumes"
c# Directory in which the backups are to be saved
backup_dir="/opt/docker_backups"
# Number of backups to be kept
keep_backups=10
# Current date and time
current_datetime=$(date +"%Y-%m-%d_%H-%M-%S")
# Name for the backup archive
backup_filename="${current_datetime}-backup.tar"
# Target server information -> SFTP location
remote_user="root"
remote_server="192.168.40.50"
remote_dir="/opt/docker_backups"
# # # # # # # # # # # # # # # # # # # # # # # #
#           End of configuration            #
# # # # # # # # # # # # # # # # # # # # # # # #

remote_target="${remote_user}@${remote_server}"
backup_fullpath="${backup_dir}/${backup_filename}"

# Shut down Docker container -> Is recommended but probably not needed as it is bad to shot down production containers
docker stop $(docker ps -q)
# Create the backup archive
tar -cpf "${backup_fullpath}" "${source_dir}"
# Restart the Docker container
docker start $(docker ps -a -q)
# Compress the backup archive
gzip "${backup_fullpath}"
backup_fullpath="${backup_fullpath}.gz"
# Copy the backup to the target server with SCP without password
scp "${backup_fullpath}" "${remote_target}:$remote_dir/"
# Delete older local backups with `find`.
find "$backup_dir" -type f -name "*-backup.tar.gz" -mtime +$keep_backups -exec rm {} \;
# Delete older remote backups with `find`.
ssh "${remote_target}" "find ${remote_dir} -type f -name '*-backup.tar.gz' -mtime +$keep_backups -exec rm {} \;"

echo "Backup has been created: ${backup_fullpath} and on ${remote_target} copied."
algora-pbc[bot] commented 1 month ago

πŸ’Ž $100 bounty β€’ CloudGakkai

πŸ’Ž $100 bounty β€’ matt.dekok

πŸ’Ž $50 bounty β€’ skye

Steps to solve:

  1. Start working: Comment /attempt #2389 with your implementation plan
  2. Submit work: Create a pull request including /claim #2389 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to coollabsio/coolify!

Add a bounty β€’ Share on socials

DeVoresyah commented 1 month ago

putting a bounty on this to make it high-priority

balmacefa commented 1 month ago

UI coolify_domain.you/settings#backup

image

Related files

https://github.com/coollabsio/coolify/blob/88581c898356e7292f999890a8aa6fff29e650ad/resources/views/livewire/settings/backup.blade.php#L11

https://github.com/coollabsio/coolify/blob/main/app/Jobs/DatabaseBackupJob.php#L30

https://github.com/coollabsio/coolify/blob/main/app/Jobs/DatabaseBackupStatusJob.php#L18

https://github.com/coollabsio/coolify/blob/88581c898356e7292f999890a8aa6fff29e650ad/app/Livewire/Project/Database/Backup/Execution.php#L10

Related blade files

https://github.com/coollabsio/coolify/tree/88581c898356e7292f999890a8aa6fff29e650ad/resources/views/livewire/project/database

DeVoresyah commented 1 month ago

UI coolify_domain.you/settings#backup

image

Related files

https://github.com/coollabsio/coolify/blob/88581c898356e7292f999890a8aa6fff29e650ad/resources/views/livewire/settings/backup.blade.php#L11

https://github.com/coollabsio/coolify/blob/main/app/Jobs/DatabaseBackupJob.php#L30

https://github.com/coollabsio/coolify/blob/main/app/Jobs/DatabaseBackupStatusJob.php#L18

https://github.com/coollabsio/coolify/blob/88581c898356e7292f999890a8aa6fff29e650ad/app/Livewire/Project/Database/Backup/Execution.php#L10

Related blade files

https://github.com/coollabsio/coolify/tree/88581c898356e7292f999890a8aa6fff29e650ad/resources/views/livewire/project/database

hi, currently coolify only supports backups for the database. instead this issue/feature request is to backup more than database

m1daz commented 1 month ago

If this will be completed, please allow options to choose drives on a server to backup to, not just S3

Thijmen commented 1 month ago

@m1daz What do you mean with drives? A local folder path, I assume?

m1daz commented 1 month ago

Yes, not on S3

w7tf commented 1 month ago

Would it make sense to allow a one click restore option? If you back up your volume data from any docker app for instance, clicking "restore" would replace the current volume with the one of the backup.

Another great option would be creating a new "resource" out of a backup. I don't know if you're familiar with Hetzner backups, but if you backup your machine, you could click "create a new machine from backup". That would spin up a new VM with the data of you backup. The exact same mechanism would come in handy with resources as well. Backup -> Create a new resource from backup -> New resource is created (with different domain and or ports)

Thijmen commented 1 month ago

I think it's important to have a clear goal here; is it also the goal to back up the volumes? If so, that can be a lot of data.

w7tf commented 1 month ago

I think it's important to have a clear goal here; is it also the goal to back up the volumes? If so, that can be a lot of data.

Indeed I'd say it is important. For stateless applications such as NextJS and Astro where you probably send your files to S3 anyways, it's not important. However for the wordpress folks where some data such as images is located outside of the database this feature would be very beneficial.

Thijmen commented 1 month ago

How would you determine per application what to backup? Only local volumes, persistent docker volumes etc?

ayntk-ai commented 1 month ago

@Thijmen @w7tf The goal is just to refactor and improve the current backup flow and add missing features. Database restore should be available for all databases, one click restore (no manual download and upload of the backup file). Almost all docker containers have volumes that are persistent and these need to be backed up which is the point of a backup, as the container is not persistent but the volumes are. and also some other enhancements life SFTP storage option not just s3.

ayntk-ai commented 1 month ago

@w7tf I added your idea as pint 17 to the feature request: https://github.com/coollabsio/coolify/issues/2389#issue-2341711069 @Thijmen

How would you determine per application what to backup? Only local volumes, persistent docker volumes etc?

There would be two checkboxes: Backup Database, Backup Container --> The backup container will backup all persistent data of the container (volumes). Updated my request for more accuracy: https://github.com/coollabsio/coolify/issues/2389#issue-2341711069

Thijmen commented 1 month ago

SFTP would be very easy, as Laravel supports that out of the box with Flysystem; https://flysystem.thephpleague.com/docs/

ayntk-ai commented 1 month ago

SFTP would be very easy, as Laravel supports that out of the box with Flysystem; https://flysystem.thephpleague.com/docs/

I see SFTP and WebDAV and some more is supported by this that is amazing.

ayntk-ai commented 1 month ago

@Thijmen If you have time to implement it, I would be more than happy to test it and make suggestions.

m1daz commented 1 month ago

How would you determine per application what to backup? Only local volumes, persistent docker volumes etc?

The things I would 100% want backed up are my postgres resource storage and a storage volume for another nodejs project. I also can't stress this enough, but I would really like local backups on specific drive mounts or folders on those drives, etc (since I have 8 different disks), not just remote ones. Coolify can be used for managing local servers too, not just cloud ones.

neo3k commented 3 weeks ago

Great job! What about resource-level backups? Being able to restore an application/resource individually.

rihards-simanovics commented 3 weeks ago

Ideally speaking I would love to see a backup/restore strategy similar to that of Plesk - a cPanel like control panel for hosting websites.

In Plesk you are able to backup the server configs, and separate subscriptions (domains and their subdomains) including the DB and the files.

Thing with Coolify is I think it was meant to be just for hosting the SPA and cold start applications which don't store much info other then DB perhaps and use S3 for block storage.

As you have docker containers and people can host projects such as WordPress, there needs to be a way to create three different backups per project:

  1. Volume/Storage;
  2. Database; and
  3. Project Configs.

Config backup is covered by the Coolify DB backups; project DB backup is covered by the additional DBs - which can be added in Coolify backup settings, albeit you must add each DB manually. This means that we only need to find a way to create a volume/storage backups.

Also, restore strategy needs consideration. With Plesk for instance, you can initialise a basic instance of Plesk and configure it enough to connect to S3 storage, then just pull the latest backup; or if you need to restore only one project, then just select that one project for restore.

I think right now the best work around is to find a PaaS that provides ability to create instance snapshots/backups of the VPS, which most thankfully do, but for extra charge, or segregate your projects to different servers. Those that need dedicated backup strategy go to server X and those don't need it go to Y.