如果rex不存在,我想用它创建一个目录。我读过这,但我找不到该怎么做。
如果在没有目录的情况下发送文件,则会得到以下错误:
ERROR - upload: /usr/local/path/file.ext is not writable有什么暗示吗?
发布于 2018-02-12 12:56:56
我认为rex书中的文档有点老了。
请看这里的https://www.rexify.org/docs/api/或(截至今天)这里的最新文档:https://www.rexify.org/docs/api/1.4/rex/commands/file.pm.html#file-file_名字-选项- (它说的是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
复制相似问题