Operations-Orchestration

如何使用 rex 創建目錄

  • April 22, 2020

rex如果它不存在,我想創建一個目錄。我讀了這個 ,但我找不到怎麼做。

如果我發送沒有目錄的文件,我會收到此錯誤:

ERROR - upload: /usr/local/path/file.ext is not writable

有什麼提示嗎?

我認為 rex 書中的文件有點舊。

請在此處查看https://www.rexify.org/docs/api/或(截至今天)此處的最新文件:
https ://www.rexify.org/docs/api/1.4/rex/commands /file.pm.html#file-file_name-options-
(它說的是版本 1.4,而目前的 cpan 版本是 1.6,但沒關係)

所以,用一個例子來回答你的問題:

task "backuptask", group => "mygroup", sub { 
   #
   # 1.) define the Backup Dir (you could do it without this step)                                                                                                                        
   my $backupdir = "/tmp/backup";  
   #                                                                                                      
   # 2.) "ensure" that the file is a (existing) "directory"        
   file $backupdir, 
           ensure=> "directory", 
           owner => "myowner", 
           group => "mygroup", 
           mode => 700, 
           on_change => sub { say "File was changed";};

   #                                                                                                                                    
   # 3.) define Backup File                                                                                                                         
   my $currTimestamp = strftime('%y%m%d',localtime);                                                                                     
   my $backupfile = "$backupdir/somebackup$currTimestamp";
   #                                                                            
   # 4.) "ensure" the the file is "present" at the defined path
   file $backupfile, ensure=> "present";

   ...execute something here...

}  ;                                                                                               

引用自:https://serverfault.com/questions/894597