当前位置:网站首页>PowerShell - batch file deferred replication
PowerShell - batch file deferred replication
2022-04-21 07:23:00 【Landscape Shepherd】
Realization function
1. Traverse the source directory .
2. Copy the source directory file to the destination directory .
3. When every time ( Every cycle ) Copy reached $file_count when , Sleep $sleep_time second .
4. Keep copying 、 Sleep , Cycle until all files are copied .
5. The program does not check whether the file will be copied successfully .
6. The program does not verify the file format in the original directory , All files will be copied , But it doesn't include the catalog .
Github Address
Source code
<#
By YeQiyu
Date 20210622
#>
<#
Update log
v1.0
By YeQiyu
Date 20210622
1. Traverse the source directory .
2. Copy the source directory file to the destination directory .
3. When every time ( Every cycle ) Copy reached $file_count when , Sleep $sleep_time second .
4. Keep copying 、 Sleep , Cycle until all files are copied .
5. The program does not check whether the file will be copied successfully .
6. The program does not verify the file format in the original directory , All files will be copied , But it doesn't include the catalog .
The program generates log files in two paths .
1. Source directory file list : Record source directory file name
2. Log files : Record the program execution process ( Copy records of specific documents are not included )
v1.1
20210623
1. Adjusted the order of method definitions . Define the method first , Call after .
2. Fixed a log Method is not set path The problem of .
3. When traversing the file , Added log output . Every read N Print a file 1 Secondary log .
#>
############### Configuration area ###############
# Number of files copied each time ( The default value is 2000)
$file_count = 2000
# Hibernation time after reaching the number of files copied each time ( Unit second . The default value is 60 second )
$sleep_time=20
# Original directory
$source_dir='F:\ Source directory ';
# Target directory
$dest_dir='D:\ Target directory ';
# Log file path
$log_dir='D:\ Log directory ';
# When traversing the file , Every read N Print a file 1 Secondary log .( The default value is 1000)
$file_check_count=1000;
############### Configuration area ###############
############### Program area ###############
$today=Get-Date;
$now = $today.ToString('yyyyMMddHHmmss');
$file_record_name=$log_dir+"\"+$now+".txt";
$log_file=$log_dir+"\log_"+$now+".log";
############### General method definition ###############
# Output log information to file
function log_write
{
Param
(
$log_file,
$log_string
)
$today=Get-Date
$now = $today.ToString('yyyy-MM-dd HH:mm:ss')
Write-Host($now+" "+$log_string);
Add-Content -path $log_file -value $now" "$log_string;
}
function file_record
{
Param
(
$log_file,
$log_string
)
Add-Content -Path $log_file -value $log_string
}
# Output log
function log
{
Param
(
$log_string
)
log_write -log_file $log_file -log_string $log_string
}
############### General method definition ###############
log -log_string " Start reading configuration ";
log -log_string Batch start :$now;
log -log_string Original directory :$source_dir;
log -log_string Target directory :$dest_dir;
log -log_string " Start traversing the original directory , Generate a list of files !";
$file_count=1;
# Generate a list of files
Get-ChildItem $source_dir |ForEach-Object -Process{
if($file_count % $file_check_count -eq 0){
log -log_string Read file :$file_count;
}
$file_count++;
if($_ -is [System.IO.FileInfo])
{
file_record -log_file $file_record_name -log_string $_;
}
}
log -log_string File list generation completed ! common $file_count Files to be copied . List file name :$file_record_name;
# Copy file
$file_list=Get-Content $file_record_name;
$count = 1;
foreach ($file in $file_list)
{
if($count % $file_count -eq 0){
log -log_string The number of copied files has reached $file_count" " Sleep $sleep_time"" second
Start-Sleep -s $sleep_time
}
Copy-Item -Path $source_dir"\"$file -Destination $dest_dir
$count++;
}
log -log_string File copy complete !
############### Program area ###############
版权声明
本文为[Landscape Shepherd]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210619114294.html
边栏推荐
- VMWare vSphere Failed to create object
- Micro Service -- service splitting strategy and principle
- 图形学基础|景深效果(Depth of Field/DOF)
- C语言版栈的应用:进制转换
- How to prevent SQL injection
- This site cannot provide a secure connection. An unsupported protocol is used
- dpdk-16.04 igb crc length 统计问题
- MySQL workbench cannot use clear text authentication over non SSL connections problem solving
- 2021年YCU蓝桥杯程序设计竞赛选拔赛题解
- Database splitting under microservice architecture
猜你喜欢

虚幻引擎之多线程渲染机制

Open platform and its technical architecture

C语言版:二叉树的静态建立

数据库——《对数据进行排序》

推荐系统笔记(杂)

Guaba and Computational Geometry

力扣-300.最长递增子序列

Add parentheses to Boolean expressions for short circuit operators

图形学基础|实时阴影渲染

Reflection cannot find the class message classnotfound of UDF when executing flinksql code
随机推荐
【保姆安装教程】Linux操作系统中源码下载MySQL5.7
虚幻引擎编程基础(二)
systemd如何使用/etc/init.d脚本
WordPress地址siteurl错误 无法登录的解决方法
Implémenter un tableau en tant que fonction JS. Prototype. Foreach (),. Map (),. Filtre ()
grub boot.S代码分析
C语言版:二叉树的静态建立
CF515B Drazil and His Happy Friends题解
彩虹(状压dp)
VMWare vSphere Failed to create object
Shader tool for 3d-max (stroke)
Integers Have Friends 区间gcd + 双指针
SQL--数据定义
图形学基础|景深效果(Depth of Field/DOF)
Reflection cannot find the class message classnotfound of UDF when executing flinksql code
Busybox initrd及初始化流程
C语言版:循环队列的建立和基本操作
【LeetCode 54 】螺旋矩阵
udevd 检索内核模块并加载的 demo
Code analysis of distributed lock principle using ZK