new transfer tasks and fixed permissions

This commit is contained in:
abrown38 committed 2025-03-21 14:13:13 +00:00
1 parent f1541c6f29
commit dc1afab15f
7 files changed
+122 -18

No files matched your search

@@ -1 +1 @@
scheduled_transfer_export_v1.3.ps1 scheduled_transfer_export_v2.0.ps1
@@ -0,0 +1,40 @@
function Main {
$log_file="T:\Logs\Export-Log.txt"
$export_dirs=Get-ChildItem -Path "S:\" -Directory -Recurse -Filter "Export"
foreach($export_dir in $export_dirs) {
$full_path="$($export_dir.FullName)"
$parent_dir="$($export_dir.Parent)"
$files=Get-ChildItem -path $full_path -File
foreach($file in $files) {
$file_path="$($file.FullName)"
$destination="T:\Export\$parent_dir\"
$size=Format-FileSize(($file_path).length)
Move-Item -Path $file_path -Destination $destination
$date=Get-Date -UFormat "[%d/%b/%y %T]"
$log_line="{0} {1} -> {2} [{3}]"-f $date, $file_path, $destination, $size
Write-Host $log_line
$log_line | out-file $log_file -Append
}
}
}
function Format-FileSize() {
Param ([int64]$size)
If ($size -gt 1TB) {[string]::Format("{0:0.00} TB", $size / 1TB)}
ElseIf ($size -gt 1GB) {[string]::Format("{0:0.00} GB", $size / 1GB)}
ElseIf ($size -gt 1MB) {[string]::Format("{0:0.00} MB", $size / 1MB)}
ElseIf ($size -gt 1KB) {[string]::Format("{0:0.00} kB", $size / 1KB)}
ElseIf ($size -gt 0) {[string]::Format("{0:0.00} B", $size)}
Else {[string]::Format("0B", $size)}
}
Main
@@ -1 +1 @@
scheduled_transfer_import_v1.3.ps1 scheduled_transfer_import_v2.0.ps1
@@ -0,0 +1,43 @@
function Main {
$import_dir="T:\Import\"
$log_file="T:\Logs\Import-Log.txt"
$files=Get-ChildItem -Path $import_dir -File -Recurse -Force -Exclude ".*"
foreach($file in $files) {
$file_name="$($file.Name)"
$parent_dir="$($file.Directory.Name)"
$Destination="S:\" + "$parent_dir" + "\import"
$size=Format-FileSize(($file).length)
$date=Get-Date -UFormat "[%d/%b/%y %T]"
if([System.IO.File]::Exists("$Destination\$file_name")) {
$log_line="{0} {1} already exists at {2}"-f $date, $file_name, $destination, $size
Write-Host $log_line
$log_line | out-file $log_file -Append
continue;
}
Move-Item -path $file -Destination $Destination
$log_line="{0} {1} -> {2} [{3}]"-f $date, $file, $destination, $size
Write-Host $log_line
$log_line | out-file $log_file -Append
}
}
function Format-FileSize() {
Param ([int64]$size)
If ($size -gt 1TB) {[string]::Format("{0:0.00} TB", $size / 1TB)}
ElseIf ($size -gt 1GB) {[string]::Format("{0:0.00} GB", $size / 1GB)}
ElseIf ($size -gt 1MB) {[string]::Format("{0:0.00} MB", $size / 1MB)}
ElseIf ($size -gt 1KB) {[string]::Format("{0:0.00} kB", $size / 1KB)}
ElseIf ($size -gt 0) {[string]::Format("{0:0.00} B", $size)}
Else {[string]::Format("0B", $size)}
}
Main
+5 -9
View File
@@ -74,22 +74,18 @@
file_system: NTFS file_system: NTFS
new_label: "{{ filetransfer_volume_label }}" new_label: "{{ filetransfer_volume_label }}"
- name: Create Import and Export directories in T drive for File Transfer script - name: Create Import, Export, and Logs directories in T drive for File Transfer script
win_file: win_file:
path: "T:\\{{ item }}" path: "T:\\{{ item }}"
state: directory state: directory
with_items: ["Import", "Export"] with_items: ["Import", "Export", "Logs"]
- name: Create logs directory in T drive
win_file:
path: "T:\\Logs"
state: directory
- name: Set permissions on logs folder on T drive - name: Set permissions on logs folder on T drive
win_acl: win_acl:
path: "T:\\logs" path: "T:\\{{ item }}"
user: file-transfer user: "{{ win_project }}\\{{ filetransfer_user }}"
type: allow type: allow
rights: Read,Write,Modify rights: Read,Write,Modify
state: present state: present
with_items: ["Import", "Export", "Logs"]
when: inventory_hostname in groups['meta-name_fs01'] when: inventory_hostname in groups['meta-name_fs01']
@@ -1,4 +1,12 @@
--- ---
- name: add user rights to file-transfer user
tags: transfer_user_rights
ansible.windows.win_user_right:
name: SeBatchLogonRight
users:
- "{{ win_project }}\\{{ filetransfer_user }}"
action: add
- name: Copy scripts to fileserver - name: Copy scripts to fileserver
tags: copy_scheduled_tasks tags: copy_scheduled_tasks
block: block:
@@ -38,6 +46,9 @@
start_boundary: "{{ task_start_time.stdout }}" start_boundary: "{{ task_start_time.stdout }}"
repetition: repetition:
interval: PT5M interval: PT5M
multiple_instances: 1
run_level: highest
start_when_available: true
- name: Create import scheduled task - name: Create import scheduled task
win_scheduled_task: win_scheduled_task:
@@ -55,4 +66,7 @@
start_boundary: "{{ task_start_time.stdout }}" start_boundary: "{{ task_start_time.stdout }}"
repetition: repetition:
interval: PT5M interval: PT5M
multiple_instances: 1
run_level: highest
start_when_available: true
when: inventory_hostname in groups['meta-name_fs01'] when: inventory_hostname in groups['meta-name_fs01']
+18 -7
View File
@@ -24,13 +24,24 @@
retries: 10 retries: 10
delay: 10 delay: 10
- name: Add file-transfer user permissions to study folder - name: file-transfer user permissions
win_acl: block:
path: "{{ study_folder }}\\export" - name: Add file-transfer user permissions to study folder
state: present win_acl:
type: allow path: "{{ study_folder }}"
user: file-transfer state: present
rights: 'FullControl' type: allow
user: file-transfer
rights: 'Read,ReadAndExecute,ListDirectory'
- name: Add file-transfer user permissions to study folder
win_acl:
path: "{{ study_folder }}\\{{ item }}"
state: present
type: allow
user: file-transfer
rights: 'Modify,Write'
loop: ["import", "export"]
- name: Remove Users permissions - name: Remove Users permissions
block: block: