小编Tha*_*you的帖子

如何使用 SSH 隧道编写数据库迁移脚本?

我正在尝试sync.sh为我们的网站创建一个与我们不太理想的版本控制相协调的脚本。此脚本会将数据库的实时副本迁移到我们的开发环境和其他一些东西。我在 mysql 迁移部分遇到了问题。

该脚本在开发机器上运行。 remote是现场主持人。

# --------------
# database

# ssh tunnel
ssh -L 3307:remote:3306 user@remote

# mysql dump
mysqldump -u someuser -h remote -P 3307 -p"p4ssw0rd" db > localfile.sql

# somehow close ssh tunnel ???

# populate local db with sql dump file
mysql -ulocal db < localfile.sql

# -----------------
# other sync stuff
# ...
Run Code Online (Sandbox Code Playgroud)

当我只运行脚本的 mysql 部分时,我得到了这个输出:

Pseudo-terminal will not be allocated because stdin is not a terminal.
Enter password: 
Run Code Online (Sandbox Code Playgroud)

我们已经设置了 ssh 密钥,我可以正确地 ssh …

ssh bash mysql shell-script ssh-tunnel

7
推荐指数
1
解决办法
5338
查看次数

如何在 zsh 中取消设置(撤消)unix set -C?

这按预期工作

$ echo "foo" > foo
$ cat foo                # foo
$ echo "updated" > foo
$ cat foo                # updated
Run Code Online (Sandbox Code Playgroud)

man set

-C      If  set, bash does not overwrite an existing file with the
        >, >&, and <> redirection operators.  This may be overridden
        when creating output files by using the redirection operator
        >| instead of >.
Run Code Online (Sandbox Code Playgroud)

好的,让我们 set -C

$ set -C
$ echo "bar" > bar
$ cat bar                # bar
$ echo "updated" > bar …
Run Code Online (Sandbox Code Playgroud)

unix zsh command-line

6
推荐指数
1
解决办法
5849
查看次数

标签 统计

bash ×1

command-line ×1

mysql ×1

shell-script ×1

ssh ×1

ssh-tunnel ×1

unix ×1

zsh ×1