2023-12-05 13:23:21 -08:00

62 lines
2.5 KiB
Markdown

<h1 align="center">Docker Backups</h1>
<p align="center">
A bash script that will stop all running containers. Create a <strong>.tar.gz</strong> files of those stopped containers then upload them to a specified save location.
</br>
After the containers are successfully saved, it will proceed to restart them.
</br>
The script will log each step of the process including the time it takes for the script to execute.
</br>
</p>
## Prerequisites
You will need to change `[USERNAME]` to the one you use on your server. You will find this in **(3)** parts of the script.
## Folder Structure
If you have not done so already, create a new folder called `scripts` in your **~home** folder. This is where all your scripts will go.
Inside your `scripts` folder create a new folder called `backups`
When done your folders structure should look like this: `/home/[username]/scripts/backups`
## Script
Get the source code from this repo and save it as `docker_backups.sh` in the **backups** folder created in the previous step.
Next we need to change the permissions of this file so that the server can read it.
1. Right click on `docker_backups.sh` then Properties.
2. Click on `Permissions` tab at top.
3. Make sure Owner & Group reflect your `username` with `Read and Write` access to all.
4. Check the `Execute` box to allow executing the file as a program.
5. Close out the window.
## Run
Now we need to test and run the script.
* Make sure your terminal is open to the location of the `docker_backups.sh` file. Should be `~/scripts/backups`
* Run the script:
```bash
bash docker_backups.sh
```
The script should be running and should be printing to the terminal what step its on. This process will take a few minutes or so depending on how many running containers you have.
## Automation
<p>
The script has to be automated so that you will have current backups incase you need them. This can be automated using <em>Linux Mint's</em> built in <a href="https://www.fosslinux.com/106902/the-guide-to-mastering-cron-jobs-in-linux-mint.htm" target="blank"><strong>Crontab</strong></a> system to create a <code>cron</code> job. <strong>Crontab</strong> is managed with the terminal and <em><strong>does not</strong></em> have a GUI.
<br /><br />
I have not found a good GUI option for crontab as of yet however, I have found and use an application called <a href="https://cronicle.net/" target="blank"><strong>Cronicle</strong></a>. Cronicle is task scheduler that functions like <strong>Crontab</strong> but only with a GUI.
<br />
<br />
</p>