- file backup from local to remote server :
tar zcf - /some/directory | ssh username@server "cat > backup.tar.gz"
or same thing, using dump instead :
tar zcf - /some/directory | ssh username@server "dd of=filename.bz2"
- output from local to remote server :
echo "some text" | ssh username@example.com "cat > somefile.txt"
or
cat ~/.ssh/id_rsa.pub | ssh username@example.com "cat >> ~/.ssh/authorized_keys"
- backup local mysql database to remote server :
mysqldump --opt database_name | gzip -c | ssh username@example.com "cat > /remote/dir/DB_backup.gz"
or using tar to backup database :
mysqldump | tar cf - | gzip -c | ssh username@example.com "cat > /remote/dir/DB_backup.tar.gz"
- execute commands on remote server :
ssh username@example.com "uname -a"
or execute commands on remote server but save the output to local :
ssh user@example.com "mysqldump -u DB_username -pDB_password DB_name | gzip -c" > /local/dir/DB_backup.gz
*** the "-p" parameter of "mysqldump" needs the value immediately after the parameter, no space.
These are just a few ways to make use of bash & ssh. You have any?
Nemaste !!!

2 comments:
I think you meant "tar zcf" for the first 2 examples. Also, the gzip in the pipeline is redundant.
Hi dave, thank you for the correction! :)
Post a Comment