diff --git a/copy_server/1-old-server.sh b/copy_server/1-old-server.sh new file mode 100644 index 0000000000000..3ab8a531ed485 --- /dev/null +++ b/copy_server/1-old-server.sh @@ -0,0 +1,6 @@ +#!/bin/bash +docker_container=$1 + +docker cp ${docker_container}:/data/git /home/user/git +docker cp ${docker_container}:/data/gitea/avatars /home/user/avatars + diff --git a/copy_server/2-host-server.sh b/copy_server/2-host-server.sh new file mode 100644 index 0000000000000..93bc0bfbc4c1b --- /dev/null +++ b/copy_server/2-host-server.sh @@ -0,0 +1,14 @@ +#!/bin/bash +origin_server=$1 +destination_server=$2 +origin_tenant=$3 + +# Copy files from origin server, probably need to be root to access /var/lib/docker/volumes +scp -r ${origin_server}:/var/lib/docker/volumes/${origin_tenant}_db-data/ ~/db-data +scp -r ${origin_server}:/home/user/git/ ~/git +scp -r ${origin_server}:/home/user/avatars/ ~/avatars + +# Paste files to destination server +scp -r ~/db-data ${destination_server}:/home/user/db-data +scp -r ~/git ${destination_server}:/home/user/git +scp -r ~/avatars ${destination_server}:/home/user/avatars diff --git a/copy_server/3-new-server.sh b/copy_server/3-new-server.sh new file mode 100644 index 0000000000000..fd1709d825022 --- /dev/null +++ b/copy_server/3-new-server.sh @@ -0,0 +1,14 @@ +#!/bin/bash +docker_container=$1 +destination_tenant=$2 + +# Copy mysql docker volume, probably need to be root to access /var/lib/docker/volumes +cp -r /home/user/db-data/_data /var/lib/docker/volumes/${destination_tenant}_db-data/_data + +# Copy /data/git/respositories and /data/gitea/avatars +docker cp /home/user/git/repositories ${docker_container}:/data/git/ +docker cp /home/user/avatars ${docker_container}:/data/gitea/ + +# Change owner from root:root to git:git +docker exec ${docker_container} chown -R git:git /data/git/repositories +docker exec ${docker_container} chown -R git:git /data/gitea/avatars diff --git a/copy_server/README.md b/copy_server/README.md new file mode 100644 index 0000000000000..b2f9eafa3b79b --- /dev/null +++ b/copy_server/README.md @@ -0,0 +1,32 @@ +## Copy dhs-gitea server +The purpose of this scripts are to copy dhs-gitea server to another dhs-gitea server. + +## Requirements +- Live origin dhs-gitea server +- Live destination dhs-gitea server + +## Scripts Breakdown +- `autorun.sh` - Run other 3 scripts and clean files. +- `1-old-server.sh` - Get all required data from origin server, run from origin server. +- `2-host-server.sh` - Transfer data from origin server to destination server, run from host machine. +- `3-new-server.sh` - Put data into destination server. + +## Usage +`autorun.sh` will automatically execute the 3 other scripts. Run it on host machine along with 6 parameters as arguments. +Then all unneeded files will be cleaned as well. + +```sh +./autorun.sh +``` + +- First arg: origin_server, ex: root@0.0.0.0 +- Second arg: origin_docker_container, ex: 5f651399aab2 +- Third arg: origin_tenant, ex: usb +- Fourth arg: destination_server, ex: root@1.1.1.1 +- Fifth arg: destination_docker_container, ex: bfd6e62fa2d0 +- Sixth arg: destination_tenant, ex: dhcs + +## Example: +```sh +./autorun.sh root@0.0.0.0 5f651399aab2 usb root@1.1.1.1 bfd6e62fa2d0 dhcs +``` \ No newline at end of file diff --git a/copy_server/autorun.sh b/copy_server/autorun.sh new file mode 100644 index 0000000000000..5898d903bf93a --- /dev/null +++ b/copy_server/autorun.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +origin_server=$1 #ex: root@0.0.0.0 +origin_docker_container=$2 #ex: 5f651399aab2 +origin_tenant=$3 #ex: usb +destination_server=$4 #ex: root@0.0.0.0 +destination_docker_container=$5 #ex: bfd6e62fa2d0 +destination_tenant=$6 #ex: dhcs + +ssh ${origin_server} ./1-old-server.sh ${origin_docker_container} +./2-host-server.sh ${origin_server} ${destination_server} ${origin_tenant} +ssh ${destination_server} ./3-new-server.sh ${destination_docker_container} ${destination_tenant} + +# Clean all files +ssh ${origin_server} "rm -rf /home/user/git /home/user/avatars" +rm -rf ~/git ~/avatars ~/db-data +ssh ${destination_server} "rm -rf /home/user/git /home/user/avatars /home/user/db-data" \ No newline at end of file