til icon indicating copy to clipboard operation
til copied to clipboard

Molecule scp

Open xluffy opened this issue 2 years ago • 0 comments

Bình thường, có thể login vào VM tạo bởi molecule như sau:

mol login
# or
mol login --host vg-ubuntu-2004-postgresql-01

Nhưng nếu muốn scp để đẩy một file vào test, ví dụ một tệp backup của PostgreSQL thì mần sao? Về cơ bản, VM molecule xài Vagrant driver, có thể dùng user vagrant để SSH, miễn sao PasswordAuthentication yes. Tuy nhiên có một nơi lưu trữ thông tin về VM đó tương tự command vagrant ssh-config

> cat /home/xluffy/.cache/molecule/postgresql/pg-13/instance_config.yml

- {address: 127.0.0.1, identity_file: \
/home/xluffy/.cache/molecule/postgresql/pg-13/.vagrant/machines/vg-ubuntu-2004-postgresql-01/virtualbox/private_key,
  instance: vg-ubuntu-2004-postgresql-01, port: '2202', user: vagrant}

- {address: 127.0.0.1, identity_file: \
/home/xluffy/.cache/molecule/postgresql/pg-13/.vagrant/machines/vg-ubuntu-2004-postgresql-02/virtualbox/private_key,
  instance: vg-ubuntu-2004-postgresql-02, port: '2203', user: vagrant}

Với thông tin này, có thể SSH bằng SSH key như sau:

> PRV_SSH="home/xluffy/.cache/molecule/postgresql/pg-13/.vagrant/machines/vg-ubuntu-2004-postgresql-01/virtualbox/private_key"
> ssh -i  "${PRV_SSH}" [email protected] -p 2202
> scp -P 2202 -i  "${PRV_SSH}" tmp/db.sql.gz [email protected]:~/

xluffy avatar Apr 20 '22 14:04 xluffy