Menu

Dipesh Majumdar

Blog and Paintings

run bash commands with spaces on pod

You wanna run bash commands with spaces in a pod without entering the pod with the '-it'  , then you need to know this - 

kubectl -n some_namespace exec mysql-passbolt-blah-blah-somemoreblah --  bash -c 'ls -ltra'

note - in the above command - double quotes can also be used.

 

you might ask -
what's the use of this ...
well the answer is - suppose you want to take a backup of a database - some_database from a mysql pod directly in your local laptop from command prompt (for ex. git bash) this is how to do it -

 kubectl -n some_namespace exec mysql-passbolt-7b976cb4cf-qmx62 --  bash -c \
'mysqldump -u root -proot_password some_database > pb.sql'

 

now how to download this file from pod to your local laptop? that's a tricky one and i spent a lot of time hunting for the exact syntax - so pay attention here... note the file name provided in the below command doesn't have any forward slash to it even though inside pod it's absolute path is /  - that's the trick - the file should be successfully downloaded now to your local machine. 

kubectl cp some_namespace/mysql-passbolt-7b976cb4cf-qmx62:pb.sql /c/Users/dipes/scripts/tmp

 

all database backup(date-wise): 

kubectl cp some_namespace/mysql-passbolt-7b976cb4cf-qmx62:pb-$(date +%Y-%m-%d).sql /c/Users/dipes/scripts/tmp

 

 

Go Back

Comment