How To Use AWK To Simplify Scripting: Multi-Database Backup Example Awkのスクリプトを使用する方法を簡素化する:マルチデータベースのバックアップの例
AWK is an extremely versatile and powerful language for processing files and text data. Awkのは、非常に多彩かつ強力な言語を処理するファイルとテキストデータです。 Often you can use awk to perform complex tasks on Unix / Linux / Mac OS command line which would otherwise take a full-fledged programming effort.頻繁に使用することができます複雑なタスクを実行するAwkのをUnix / Linux /他のMac OSのコマンドラインには本格的なプログラミングの努力を取る。 AWK is great for log processing, creating custom scripts which will then be executed and more. Awkのログ処理は素晴らしいですが、カスタムスクリプトの作成になり、その後に実行され、他のです。 For example I wanted to create a backup of all of my MySQL databases, each to a separate file after compressing them with gzip (maximum compression).たとえばしたかったのすべてのバックアップを作成するに私のMySQLデータベースは、各した後、別のファイルを圧縮してgzip形式(最大圧縮) 。 I already created a list of databases on my MySQL server is a file named databases (how original!).私は既にデータベースのリストを作成して名前のファイルをMySQLサーバは、 データベース (どのようオリジナル! )です。 Here is the awk script which processes the file and creates another file (named database_backup) which contains commands to backup all the databases as specified above.ここでは、 Awkのスクリプトを処理してファイルを別のファイルを作成(名前database_backup )が含まれ、すべてのデータベースのバックアップとしてのコマンドを指定します。
awk '{print "mysqldump -u root -p --opt",$1,"|gzip -9 >",$1 ".sql.gz"}' < databases > database_backup Awkの' (印刷"のmysqldump - uルート- p -選ぶ" 、 $ 1 、 " | g zip形式- 9> " 、 $ 1 " 。 s ql.gz" ) " <データベース> d atabase_backup I actually use a slightly modified script where I specify the password after -p so I don’t have to type it every time and also enables me to run this as a cron job.私、実際に若干の変更を使用するスクリプトを指定してパスワードをした後どこを持っていないので- pを入力することも可能にするたびに、これをメインcronジョブを実行する。
Filed under提出されて Databaseデータベース , 、 Headline Newsニュースの見出し , 、 How Toどのように , 、 Linuxリナックス , 、 MySQL MySQLの , 、 Programmingプログラミング , 、 Webウェブ | |
| |
RSS 2.0 RSS 2.0を | |
Trackbackトラックバック this Article |この記事|
Email this Article電子メールこの記事
You may also like to readを読むようにすることも可能 |




