發生災難時,我們難保雲端主機不會整個掛掉,造成連SSH都無法的窘境,
這個時候只剩下唯一的方法來救資料,那就是建立新的雲端主機,對舊主機做Snapshot或images。以外接硬碟的形式掛載在新的雲端主機上,透過mount的方式來存取舊資料。
以下是相關的指令:

建立一個虛擬資料夾,以下名為mount_directory_name

sudo mkdir -p /mnt/disks/mount_directory_name

用來看外接硬碟的實際路徑,假設是/dev/sdb1

sudo lsblk

將實體路徑掛載在虛擬資料夾上

sudo mount -o discard,defaults /dev/sdb1 /mnt/disks/mount_directory_name

賦予所有使用者權限

sudo chmod a+w /mnt/disks/mount_directory_name

如果你剛好遇到mysql資料庫需要從檔案還原,可以參考以下的單一資料庫復原的方式:

sudo cp -rf /mnt/disks/mount_directory_name/var/lib/mysql/databaseName /var/lib/mysql/
sudo chown -R mysql:mysql /var/lib/mysql/databaseName
sudo chown -R 660 /var/lib/mysql/databaseName
sudo chown mysql:mysql /var/lib/mysql/databaseName
sudo chmod 700 /var/lib/mysql/databaseName

As a newbie of Rails, we might need to try this web application on AWS server, especially AWS providing Free tier Server for us. I use t2.micro as a testing server in this scenario.

Step One—Install Ruby
1. sudo yum install ruby (in my server, ruby is already installed, you may check by using this command)

Install necessary packages and libraries
2. sudo yum install gcc g++ make automake autoconf curl-devel openssl-devel zlib-devel httpd-devel apr-devel apr-util-devel sqlite-devel

3. sudo yum install ruby-rdoc ruby-devel

Step Two—Install Ruby Gems
4. sudo yum install rubygems

Step Three—Install Rails
5. sudo gem update

6. sudo gem update –system

7. sudo gem install rails

Step 8 lacking repositories
8. gem install io-console
9. gem install json
10. sudo yum install nodejs npm –enablerepo=epel

Step 9 remember to open port 3000 from AWS security Group

Step 10 Try to create a blog web application
11. cd /home/ec2-user
12. rails new blog
13. cd blog

Step 11 Start the server!
14. rails server

Step 12 Open your browser and take a look
15 http://x.x.x.x:3000

 

15. cd /home/ec2-user/blog

16. vi Gemfile

17. add “gem ‘io-console'” at the top of the file, so that you can execute “rails generate controller welcome index”