-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.sh
More file actions
36 lines (27 loc) · 1.07 KB
/
backup.sh
File metadata and controls
36 lines (27 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# Get hostname and modify it as per rules (lowercase and replace - with _)
folder_name=$(hostname | tr '[:upper:]' '[:lower:]' | tr '-' '_')
#install pv and pixz
sudo apt-get install pv pixz
# Generate SSH key and copy it to remote server
echo -e "\nGenerating SSH key and copying to server..."
ssh-keygen -f ~/.ssh/id_rsa -q -N ""
ssh-copy-id [email protected]
# Stop services
echo -e "\nStopping services..."
systemctl stop docker.socket
systemctl stop docker
systemctl stop runpod
systemctl disable docker.socket
systemctl disable docker
systemctl disable runpod
systemctl mask docker.socket
systemctl mask docker
systemctl mask runpod
# Check and create folder if it does not exist
echo -e "\nEnsuring the backup folder exists on remote server..."
ssh [email protected] "mkdir -p /mnt/user/backup/$folder_name"
# Tar the folder /var/lib/docker and send it to the server
echo -e "\nSending the tar file to server..."
tar -c -I 'pixz -k -0' -f - /var/lib/docker | pv | ssh [email protected] "cat > /mnt/Data2/Backup/$folder_name/docker.tar.pixz"
echo -e "\nDone!"