尝试在 Rackspace 站点上使用 Perl cron 作业备份我们的数据库。
Rackspace 举了一个例子:
#!/bin/sh
mysqldump -h DB_HOST -u DB_USER -p'DB_PASSWORD' DB_NAME > YOUR_WEB_ROOT/db_backup.sql
gzip -f YOUR_WEB_ROOT/db_backup.sql
这很好,但我想在文件名中加上时间戳。我有这段代码生成时间戳:
use strict;
use warnings;
use DateTime;
my $dt = DateTime->now;
my $date = $dt->ymd;
my $time = $dt->hms;
my $file = "****.com/db_backups/db_backup - $date $time.sql";
print $file;
最终产品:
#!/bin/sh
use strict;
use warnings;
use DateTime;
my $dt = DateTime->now;
my $date = $dt->ymd;
my $time = $dt->hms;
my $file = "****.com/db_backups/db_backup - $date $time.sql";
print $file;
mysqldump -h hosturl -u username -p'password' database > $file;
gzip -f $file;
当它运行时,我得到这些错误。
/mnt/stor09-wc1-ord1/758094/****.com/backup.sh: line 2: use: command not found
/mnt/stor09-wc1-ord1/758094/****.com/backup.sh: line 3: use: command not found
/mnt/stor09-wc1-ord1/758094/****.com/backup.sh: line 4: use: command not found
/mnt/stor09-wc1-ord1/758094/****.com/backup.sh: line 5: my: command not found
/mnt/stor09-wc1-ord1/758094/****.com/backup.sh: line 6: my: command not found
/mnt/stor09-wc1-ord1/758094/****.com/backup.sh: line 7: my: command not found
/mnt/stor09-wc1-ord1/758094/****.com/backup.sh: line 8: my: command not found
/mnt/stor09-wc1-ord1/758094/****.com/backup.sh: line 9: print: command not found
/mnt/stor09-wc1-ord1/758094/****.com/backup.sh: line 10: $file: ambiguous redirect