在rails中用backup数据备份-dropbox篇

1.申请dropbox的api_key与api_secret

打开https://www.dropbox.com/developers/apps申请

第一步

点击右上角的”Create app“

第二步

点击右下角的”Create app“

第三步

第四步

复制App key与App secret 到下面的置文件中

打开config/backup/models/my_backup.rb 添加dropbox配置

config/backup/models/my_backup.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Model.new(:my_backup, 'Description for my_backup') do
  ... ...

  ##
  # Dropbox [Storage]
  #
  # Your initial backup must be performed manually to authorize
  # this machine with your Dropbox account. This authorized session
  # will be stored in `cache_path` and used for subsequent backups.
  #
  store_with Dropbox do |db|
    db.api_key     = "my_api_key"     #把App key复制到这里
    db.api_secret  = "my_api_secret"  #把App secret复制到这里
    # Sets the path where the cached authorized session will be stored.
    # Relative paths will be relative to ~/Backup, unless the --root-path
    # is set on the command line or within your configuration file.
    db.cache_path  = ".cache"
    # :app_folder (default) or :dropbox
    db.access_type = :app_folder
    db.path        = "backups"
    db.keep        = 25
  end

  ... ...
end

第五步

运行备份同步脚本

config/backup/models/my_backup.rb
1
2
cd rails_app
$ backup perform -t my_backup -c 'config/backup/my_config.rb'

第六步

oauth授权与运行成功

https://www.dropbox.com/1/oauth/authorize?oauth_token=FepGwVGFYvMAgtvj 用到浏览器打开

点击”允许“

授权成功

回到命令行,按”回车“键 继续!

搞定,查看下!dorpbox目录,已经同步好了!

config/backup/models/my_backup.rb
1
2
3
4
5
6
7
8
9
[~/Dropbox/应用/backuprb] $ tree
.
├── Icon\r
└── backups
    └── my_backup
        └── 2014.05.03.16.09.25
            └── my_backup.tar

3 directories, 2 files

ref:

原文地址:http://dlj.bz/IV3v3U

Comments