mirror of
https://github.com/zebrajr/docker-stack-backupper.git
synced 2025-12-06 00:20:24 +01:00
update scripts, readme, gitignore and sample
This commit is contained in:
parent
111bea4f68
commit
bab7d6c767
8
.env.sample
Normal file
8
.env.sample
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# Remote Server Information
|
||||
REMOTE_USER=your_username
|
||||
REMOTE_HOST=your_server_address
|
||||
|
||||
# Will be created under the Remote User Home Directory eg: docker-stack-backupper
|
||||
REMOTE_PATH=folder_path_starting_from_/home/user
|
||||
# Root folder for your docker-stack volumes eg: /opt/docker-stack/{archive, dashboard, wiki, website}
|
||||
REMOTE_DIRECTORY_BACKUP=/opt/docker-stack
|
||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.env
|
||||
data
|
||||
*.tar.gz
|
||||
51
README.md
51
README.md
|
|
@ -1,2 +1,51 @@
|
|||
# docker-stack-backupper
|
||||
Scripts to help backing up Docker Volumes and Images from VPS (usually Cloud) to other systems (usually local)
|
||||
### Overview
|
||||
|
||||
This toolkit comprises a set of Bash scripts designed to facilitate the backup and restoration of server files and Docker containers. The scripts are built to interact with a remote server, create backups of specified directories and running Docker containers, and retrieve these backups to a local machine.
|
||||
|
||||
### Prerequisites
|
||||
- Bash
|
||||
- Docker (for Docker-related operations)
|
||||
- Access to a remote server with SSH
|
||||
- Sudo privileges on the machine where the scripts are run
|
||||
|
||||
### Configuration
|
||||
Copy the ``.env.sample`` into ``.env`` and add your own values
|
||||
|
||||
|
||||
|
||||
### Scripts Description
|
||||
1. 01_copy_to_remote.sh
|
||||
|
||||
Copies specified files or directories to a remote server.
|
||||
|
||||
2. 02_tar_folders.sh
|
||||
|
||||
Creates tar.gz backups of each folder in a specified directory and changes the ownership to a user defined in .env.
|
||||
|
||||
3. 03_export_running_docker_images.sh
|
||||
|
||||
Exports all currently running Docker container images as tar.gz files.
|
||||
|
||||
4. 04_copy_backups_local.sh
|
||||
|
||||
Retrieves tar.gz backups from the remote server to the local machine.
|
||||
|
||||
### Usage
|
||||
Run the scripts in order.
|
||||
|
||||
``01_copy_to_remote.sh`` and ``04_copy_backups_local.sh`` are to be run on your local machine (copy to, copy from)
|
||||
|
||||
``02_tar_folders.sh`` and ``03_export_running_docker_images.sh`` are to be run on the machine that is being backed up (backup data, backup images)
|
||||
|
||||
|
||||
### Contribution
|
||||
|
||||
Contributions to this project are welcome. Please follow the standard Git workflow - fork the repository, make your changes, and submit a pull request.
|
||||
|
||||
### License
|
||||
|
||||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
||||
|
||||
|
||||
Made by me - [CarlosSousa.tech](https://carlossousa.tech)
|
||||
9
scripts/01_copy_to_remote.sh
Executable file
9
scripts/01_copy_to_remote.sh
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
source ../.env
|
||||
|
||||
# Ensure the target directory exists on the remote server
|
||||
ssh ${REMOTE_USER}@${REMOTE_HOST} "mkdir -p /home/${REMOTE_USER}/${REMOTE_PATH}"
|
||||
|
||||
# Copy specified files/folders to the remote server
|
||||
scp -r ../scripts ${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_PATH}
|
||||
scp -r ../.env ${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_PATH}
|
||||
12
scripts/02_tar_folders.sh
Executable file
12
scripts/02_tar_folders.sh
Executable file
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
source ../.env
|
||||
|
||||
current_date=$(date +%Y-%m-%d)
|
||||
mkdir -p /home/${REMOTE_USER}/${REMOTE_PATH}/data/${current_date}
|
||||
|
||||
# Tar.gz each folder in the target directory
|
||||
for dir in ${REMOTE_DIRECTORY_BACKUP}/*/; do
|
||||
echo "Backing Up: ${dir}"
|
||||
sudo tar -czf "/home/${REMOTE_USER}/${REMOTE_PATH}/data/${current_date}/$(basename "$dir").tar.gz" -C "$dir" .
|
||||
sudo chown ${REMOTE_USER}:${REMOTE_USER} "/home/${REMOTE_USER}/${REMOTE_PATH}/data/${current_date}/$(basename "$dir").tar.gz"
|
||||
done
|
||||
11
scripts/03_export_running_docker_images.sh
Executable file
11
scripts/03_export_running_docker_images.sh
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
source ../.env
|
||||
|
||||
current_date=$(date +%Y-%m-%d)
|
||||
mkdir -p /home/${REMOTE_USER}/${REMOTE_PATH}/images/${current_date}
|
||||
|
||||
# List and export all Docker images
|
||||
docker ps --format "{{.Image}}" | while read image; do
|
||||
echo "Backing Up: ${image}"
|
||||
sudo docker save "$image" | gzip > "/home/${REMOTE_USER}/${REMOTE_PATH}/images/${current_date}/${image//\//_}.tar.gz"
|
||||
done
|
||||
6
scripts/04_copy_backups_local.sh
Executable file
6
scripts/04_copy_backups_local.sh
Executable file
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash
|
||||
source ../.env
|
||||
|
||||
# Copy backups from remote server to local machine
|
||||
scp -r ${REMOTE_USER}@${REMOTE_HOST}:/home/${REMOTE_USER}/${REMOTE_PATH}/data ../
|
||||
scp -r ${REMOTE_USER}@${REMOTE_HOST}:/home/${REMOTE_USER}/${REMOTE_PATH}/images ../
|
||||
Loading…
Reference in New Issue
Block a user