成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

Backup Database and Other Attachments in ROR

WrBug / 2000人閱讀

摘要:定時任務(wù)命令詳解

Related Resources

rsync:http://rsync.samba.org/

Crontab:http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5

"Linux Crontab 定時任務(wù) 命令詳解":http://blog.csdn.net/tianlesoftware/article/details/5315039

[rubygem]"backup":https://github.com/meskyanichi/backup

[rubygem]"whenever":https://github.com/javan/whenever

Automatically backup on the remote server:

Let"s firstly assumpt:

You have a site named "example.com";

You can login to it through a username "deploy", and its password is "password";

You located the contents of your site in /var/www/example/;

Your database server is Mysql, and the database for your site is example_production.

1. SSH login:

$ ssh [email protected]

2. Install the backup:

$ gem install backup

3. Prepare directories for backup files:

$ mkdir /var/www/example/backup
$ mkdir /var/www/example/backup/db

4. Generate and edit backup script:

$ cd ~/
$ mkdir Backup/
$ cd Backup
$ backup generate:model -t example_db --databases=mysql --compressors=gzip --storages=local
$ cd models
$ vim example_db.rb

Input the below content:

# encoding: utf-8

Backup::Model.new(:example_db, "Dumping example Production Database") do
  split_into_chunks_of 250

  database MySQL do |db|
    db.name               = "example_production"
    db.username           = ""                      # Replace the blank string with your real username
    db.password           = ""                      # Replace the blank string with your real password
    db.host               = "localhost"
    db.port               = 3306
    db.socket             = "/var/run/mysqld/mysqld.sock"
    db.additional_options = ["--quick", "--single-transaction"]
  end

  store_with Local do |local|
    local.path       = "/var/www/example/backup/db"
    local.keep       = 10
  end

  compress_with Gzip
end

Run backup command to confirm that your config works:

backup perform -t example_db

Attention: Remember to update the config file if you have changed the username and/or password of the database.

5. Install whenever:

$ gem install whenever

6. Generate a schedule.rb file with whenever:

$ cd /var/www/example/
$ mkdir config
$ wheneverize .

The last command will create a new file named "schedule.rb" under config/ directory.

7. Add a daily task:

Open the file to edit:

vim config/schedule.rb

Contents:

set :output, "~/Backup/example_whenever.log"           # This is important, it can help you to find the reason when failed to backup the database
every :day do
  command "cd ~/Backup && backup perform -t example_db"
end

8. Update whenever task into crontab:

$ whenever --update-crontab

9. Check whether the task is updated successfully or not:

$ crontab -e

If successed, you should see your new task shown at the bottom of the file.

Synchronize remote backups every day automatically by rsync and crontab:

Attention: Below operations are played on a different server, which is used to sync files. We assumpt its domain is another.com and the username is deploy.

1. SSH login:

$ ssh [email protected]

2. Write a synchronize shell script:

$ mkdir ~/backup/example.com
$ cd ~/backup/example.com
$ vim sync.sh

Input the below contents into the new file named "sync.sh":

#! /bin/bash
cd /home/deploy/backup/example.com/

rsync -av -e "ssh" [email protected]:/var/www/example/backup/db/example_db/ db/

rsync -av -e "ssh" [email protected]:/var/www/example/shared/public/uploads .

rsync -av -e "ssh" [email protected]:/var/www/example/shared/log .

and then, assign the scripe execution authority:

$ chmod 775 sync.sh

Run the script to ensure everything works well:

$ ./sync.sh

Attention: Because it is required to be authorized to access the targer server, you should remember to copy your ssh public key to the target server(such as, example.com) before you can sync files.

3. Open user"s crontab config file:

$ crontab -e

Append the below task at the end:

10 0 * * * /home/deploy/backup/example.com/sync.sh

Ok, that"s all. The rest work is that remember to check if there is any backups generated.

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/17447.html

相關(guān)文章

  • dubbo源碼解析(二十)遠(yuǎn)程調(diào)用——Filter

    摘要:源碼分析一該過濾器是對記錄日志的過濾器,它所做的工作就是把引用服務(wù)或者暴露服務(wù)的調(diào)用鏈信息寫入到文件中。然后返回,再清空,這樣是因為后面的調(diào)用鏈中的附加值對前面的調(diào)用鏈?zhǔn)遣豢梢姷摹? 遠(yuǎn)程調(diào)用——Filter 目標(biāo):介紹dubbo-rpc-api中的各種filter過濾器的實現(xiàn)邏輯。 前言 本文會介紹在dubbo中的過濾器,先來看看下面的圖: showImg(https://segmen...

    cheukyin 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<