サーバーのドキュメント ルートとデータベースの即時バックアップを作成し、それをターミナル システムにコピーするスクリプト ファイルがあります。そこから、サーバー環境に SSH トンネルで接続します。
(
cd /var/www/html
zip -r ./html.zip ./
mysqldump -u USER -p PASSWORD --all-databases > ./db.sql
zip backup.zip html.zip db.sql
scp backup.zip /home/user/backups
rm ./html.zip ./db.sql ./backup.zip
)
私の問題:
PASSWORD の場合は、パスワードを手動で入力する必要があります。このパスワードは頭の中に定着しており、頻繁に使用しているため、スクリプト内で入力したくないので、これを避けたいのです。
私の理想:
次のコマンド (またはそれに類するもの) を実行するたびに、パスワードの入力を求められる方が望ましいです。
mysqldump -u USER --all-databases > ./db.sql
私の質問:
このようなプロンプトは、Linux 自体または既存のユーティリティを介して表示できますか?
答え1
mysqldump のマニュアルページから:
o --password[=password], -p[password]
The password to use when connecting to the server. If you use the short option form (-p), you cannot have a space between the option and the password. If you omit the password value following the
--password or -p option on the command line, mysqldump prompts for one.
Specifying a password on the command line should be considered insecure. You can use an option file to avoid giving the password on the command line.
フラグ内のパスワード値を省略する-p
と、mysqldump はパスワードを要求します。