我正在尝试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 …
这按预期工作
$ 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)