Created
November 9, 2016 04:45
-
-
Save ishideo/7de1573b580030b08333ee62edd7c1a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package backup; | |
use File::Copy; | |
use strict; | |
#backupを保存するフォルダ | |
my $backup_dir = "db/backup"; | |
#backup::filecopy($file);#$file : コピーするファイル名 | |
sub filecopy { | |
my $file = shift; | |
my $backup = $file; | |
#パスからファイル名を取得 | |
$backup =~ s/^.*\/(.*)\..*$/$1/; | |
my $num = setNumber($backup_dir."/".$backup."_count.txt"); | |
copy($file,$backup_dir."/".$backup.$num); | |
} | |
sub setNumber { | |
my $count_txt = shift; | |
my $count; | |
open(OUT, "+<"."$count_txt"); | |
flock(OUT,2); | |
open(IN, "$count_txt"); | |
$count = <IN>; | |
close(IN); | |
$count++; | |
$count ="1" if ($count le 10); | |
my $old = select(OUT); $| = 1; select($old); | |
print OUT $count; | |
truncate(OUT, tell(OUT)); | |
close(OUT); | |
return $count; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment