Hi,
As a Network Admin I always worry about my backups. I was planning to write a simple script which create a new folder by date and copy the desired files and folder in to it recursively.
so i successfully able to write a script for it and sharing it with you and I hope it is useful to you too. {or at least for tally administrators they always worried about there data, or we can say they this article contain “How to Automate Tally Backup”
I am running this script on my Tally server:
Script Logic:
- Map a Network Drive where you want to save the backup
- Create a Folder by using Date as Name
- Copy the backup
- Create a log file name as “backup_log.txt”
- When all some send a email to admin ($to) with backup_log.txt as attachment.
- Remove the Map Drive
Note : change \\T_server\Tally with your folder where you want to take backup.
Change $source with your source folder which you want to backedup
Script:
1: #System Variable for backup Procedure
2: $date = Get-Date -Format d.MMMM.yyyy
3: New-PSDrive -Name "Backup" -PSProvider Filesystem -Root "\\T_Server\Tally"4: $source = "D:\Tally\Data\"
5: $destination = "backup:\$date"
6: $path = test-Path $destination7: #Email Variables8: $smtp = "Exchange-server"
9: $from = "Tally Backup <tally.backup@xyz.com>"
10: $to = "Aman Dhally <amandhally@gmail.com>"
11: $body = "Log File of TALLY bacupk is attached, backup happens on of Date: $date"
12: $subject = "Backup on $date"
13: # Backup Process started14: if ($path -eq $true) {
15: write-Host "Directory Already exists"16: Remove-PSDrive "Backup"
17: } elseif ($path -eq $false) {18: cd backup:\19: mkdir $date20: copy-Item -Recurse $source -Destination $destination21: $backup_log = Dir -Recurse $destination | out-File "$destination\backup_log.txt"22: $attachment = "$destination\backup_log.txt"
23: #Send an Email to User24: send-MailMessage -SmtpServer $smtp -From $from -To $to -Subject $subject -Attachments $attachment -Body $body -BodyAsHtml25: write-host "Backup Sucessfull"26: cd c:\27: Remove-PSDrive "Backup"
28: }
I hope it may be useful to someone :)
Thanks
Aman Dhally