Rsync 显示文件已同步但无法在 AWS S3 中找到它

Rsync shows files are synced but could not find it in AWS S3

我在 Rails 3.2.14 上使用 capistrano 3Ruby,Ruby2.1.0。我写了一个 recipe 来检查 S3 挂载状态,然后 运行 一组特定的操作:

  1. 如果卸载存储桶并且文件夹(public/system) 为空,则使用s3fs
  2. 装载它
  3. 如果已卸载存储桶且文件夹不为空,则使用 rsync 将文件从 public/system 移动到 s3 存储桶,然后清空文件夹 public/system 并重新安装它。

rsync 显示文件是递增发送的,但我在存储桶中找不到它们。这是我得到的输出:

  05 rsync -av /home/deploy/unmounted /home/deploy/mounted
  05 sending incremental file list
  05 unmounted/
  05 unmounted/ckeditor/
  05 unmounted/ckeditor/pictures/
  05 unmounted/ckeditor/pictures/16736/
  05 unmounted/ckeditor/pictures/16736/bike.jpg
  05 unmounted/ckeditor/pictures/16736/content_bike.jpg
  05 unmounted/ckeditor/pictures/16736/thumb_bike.jpg
  05
  05 sent 750,943 bytes  received 93 bytes  166,896.89 bytes/sec
  05 total size is 750,396  speedup is 1.00

安装 s3 的方法,我还没有优化它,因为首先我只是想检查它是否工作,

desc "Mounting S3"
    task :mounting_s3 do
        on main_server, in: :sequence, wait: 5 do |host|
            as 'deploy' do
                within "#{code_folder_path}/current" do
                    code_folder = "#{code_folder_path}/current"
                    path = "#{code_folder_path}/current/public/system"
                    unmount_path = "#{code_folder_path}/shared/public/system"

                    # check first if public/system exists
                    puts "** Checking if public/system folder exists on #{host}"
                    puts "** testing if it is there #{test("[ -d #{path} ]")}"
                    if test("[ -d #{path} ]")
                        puts "** public/system folder exists.."
                        puts "** Checking if S3 is mounted"
                        result = capture "cd #{code_folder} && mountpoint public/system" , raise_on_non_zero_exit: false
                        puts "result #{result}"
                        if  result.match('is a mountpoint') != nil
                            puts "** S3 is mounted at #{path} on #{host}"
                        elsif result.match('is not a mountpoint') != nil
                            puts "** #{path} is not a mountpoint on #{host}"
                            result = capture "ls -A #{unmount_path}"
                            if result.length > 0
                                puts "** public/system is not empty"
                                if test("[ -d /home/deploy/mounted ]")

                                    puts "** mounted folder exists"

                                    puts "checking if folder is mounted"
                                    result = capture "mountpoint /home/deploy/mounted" , raise_on_non_zero_exit: false
                                    puts "result #{result}"

                                    if  result.match('is a mountpoint') != nil
                                        puts "** mounted folder is mounted so unmounting it"
                                        execute! "fusermount -u /home/deploy/mounted"
                                        puts "** mounted folder is unmounted now"

                                        puts "** Deleting mounted folder"
                                        execute! "cd /home/deploy/ && sudo rm -r mounted"
                                        puts "** mounted folder deleted"

                                    elsif result.match('is not a mountpoint') != nil

                                        puts "** Deleting mounted folder"
                                        execute! "sudo rm -r /home/deploy/mounted"
                                        puts "** mounted folder deleted"

                                    end
                                end

                                if test("[ -d /home/deploy/unmounted ]")
                                    puts "** deleting unmounted folder"
                                    execute! "cd /home/deploy/ && sudo rm -r unmounted"
                                    puts "** unmounted folder deleted"
                                end

                                puts "** mounting bucket"
                                execute! "cd /home/deploy/ && mkdir unmounted && mkdir mounted"
                                execute! "s3fs s3_bucket /home/deploy/mounted"
                                puts "** bucket mounted on /home/deploy/mounted folder"

                                puts "** copying files from public/system to unmounted"
                                execute! "cp -r #{unmount_path}/* /home/deploy/unmounted/."
                                puts "** files copied"

                                puts "** syncing unmounted files to s3"
                                execute! "rsync -av /home/deploy/unmounted /home/deploy/mounted"
                                puts "** Files synced"

                                puts "** unmounting mounted folder now for safety"
                                execute! "fusermount -u /home/deploy/mounted"
                                puts "** folder unmounted"

                                puts "** deleting unmounted folder now"
                                execute! "sudo rm -r /home/deploy/unmounted"
                                puts "** folders deleted\n"

                                puts "** emptying public/system"
                                execute! "sudo rm -r #{unmount_path}/../system/*"
                                puts "** folder is empty, mounting public/system"

                                execute! "s3fs s3-bucket #{path}"
                                puts "** s3 is mounted"
                            else
                                puts "** public/system is empty"
                                execute! "cd #{code_folder} && s3fs s3-bucket #{path}"
                                puts "** s3 is mounted"
                            end 

                        end 
                    else
                        puts "** public/system folder does not exists.."
                        puts "** Mounting S3"
                        execute! "cd #{code_folder} && s3fs s3-bucket #{path}"
                    end 
                end
            end

我在运行宁cap staging deploy:mounting_s3 --trace之后得到的输出:

** Invoke www_data (first_time)
** Execute www_data
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke rvm:hook (first_time)
** Execute rvm:hook
** Invoke rvm:check (first_time)
** Execute rvm:check
rvm 1.27.0 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
ruby-2.1.0
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]
** Invoke bundler:map_bins (first_time)
** Execute bundler:map_bins
** Invoke deploy:set_rails_env (first_time)
** Execute deploy:set_rails_env
** Invoke deploy:set_linked_dirs (first_time)
** Execute deploy:set_linked_dirs
** Invoke deploy:set_rails_env 
** Invoke deploy:mounting_s3 (first_time)
** Execute deploy:mounting_s3
** Checking if public/system folder exists on webby
** testing if it is there true
** public/system folder exists..
** Checking if S3 is mounted
result public/system is not a mountpoint
** /home/deploy/apps/web_cc_cap1/current/public/system is not a mountpoint on webby
** public/system is not empty
** mounted folder exists
checking if folder is mounted
result /home/deploy/mounted is not a mountpoint
** Deleting mounted folder
00:00 deploy:mounting_s3
      01 sudo rm -r /home/deploy/mounted
    ✔ 01 webby 0.649s
** mounted folder deleted
** mounting bucket
      02 cd /home/deploy/ && mkdir unmounted && mkdir mounted
    ✔ 02 webby 0.631s
      03 s3fs s3-bucket /home/deploy/mounted
    ✔ 03 webby 0.619s
** bucket mounted on /home/deploy/mounted folder
** copying files from public/system to unmounted
      04 cp -r /home/deploy/apps/web_cc_cap1/shared/public/system/* /home/deploy/unmounted/.
    ✔ 04 webby 0.651s
** files copied
** syncing unmounted files to s3
      05 rsync -av /home/deploy/unmounted /home/deploy/mounted
      05 sending incremental file list
      05 unmounted/
      05 unmounted/ckeditor/
      05 unmounted/ckeditor/pictures/
      05 unmounted/ckeditor/pictures/16736/
      05 unmounted/ckeditor/pictures/16736/bike.jpg
      05 unmounted/ckeditor/pictures/16736/content_bike.jpg
      05 unmounted/ckeditor/pictures/16736/thumb_bike.jpg
      05
      05 sent 750,943 bytes  received 93 bytes  166,896.89 bytes/sec
      05 total size is 750,396  speedup is 1.00
    ✔ 05 webby 4.299s
** Files synced
** unmounting mounted folder now for safety
      06 fusermount -u /home/deploy/mounted
    ✔ 06 webby 0.631s
** folder unmounted
** deleting unmounted folder now
      07 sudo rm -r /home/deploy/unmounted
    ✔ 07 webby 0.621s
** folders deleted
** emptying public/system
      08 sudo rm -r /home/deploy/apps/web_cc_cap1/shared/public/system/../system/*
    ✔ 08 webby 0.649s
** folder is empty, mounting public/system
      09 s3fs s3-bucket /home/deploy/apps/web_cc_cap1/current/public/system
    ✔ 09 webby 0.623s
** s3 is mounted

为什么不将文件发送到 s3 存储桶?

我实际上犯了一个错误,我的意图是复制 unmounted 文件夹的内容而不是 文件夹 本身。所以我修复了 rsync 代码:rsync -av /home/deploy/unmounted/* /home/deploy/mounted 并且它按预期工作。