-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy-container-from-other-machine.bash
More file actions
executable file
·93 lines (62 loc) · 1.59 KB
/
copy-container-from-other-machine.bash
File metadata and controls
executable file
·93 lines (62 loc) · 1.59 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
set -euo pipefail
readonly DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
cd $DIR
if [[ "$(whoami)" != "root" ]]
then
echo "Please run this as root"
exit 1
fi
if [[ $# -lt 2 ]]
then
echo "
Copy a container from another desktop machine to your desktop machine
NOTE:
* the machine we are copying from must have passwordless SUDO set up
Usage:
$0 [other host IP or configured hostname] [container name] (optional: other host SSH port)
"
exit 1
fi
otherHost="$1"
containerName="$2"
otherHostPort="${3:-22}"
readonly containerPath=/var/lib/lxc/$containerName
if [[ -d $containerPath ]]
then
echo "
ERROR - this container already exists on your machine
You need to remove it before running this script
"
exit 1
fi
echo "
Testing we can SSH as root to $otherHost
"
set +e
ssh "$otherHost" -p "$otherHostPort" -o StrictHostKeyChecking=no exit
canSshExitCode=$?
set -e
if (( canSshExitCode != 0 ))
then
echo "Failed to SSH as root to $otherHost"
exit 1
fi
echo "Making sure we have pv installed"
if [[ "" = "$(command -v pv)" ]]
then
dnf -y install pv
fi
echo "
Making sure the container is not running on $otherHost
"
ssh -p "$otherHostPort" "$otherHost" -- "sudo \lxc-stop -n $containerName || true"
echo "
Piping the container tar over SSH
please wait ...
"
ssh "$otherHost" -p "$otherHostPort" -- "sudo bash -xc 'tar --numeric-owner -czf - $containerPath'" | pv | sudo tar -C / --numeric-owner -xzf -
echo "
The files for $containerName are now copied,
however you may need to do further configuration to allow the container to run
"