I need help with backing up files from the command line. We have a shared folder in the office containing numerous files and subfolders. Currently, I perform full backups every morning, which is not efficient because most files remain unchanged for days.
I have decided to backup only files created and modified the previous day. However, I cannot find a solution that deals with the “date created” attribute of files.
For instance, if a user creates a file on their desktop a week ago and copies it to the shared folder yesterday, it won’t be included in the backup because its “date modified” is a week ago, and its “date created” is the date it was copied on.
Similarly, if a user moves a file to the shared folder yesterday, the “date created” and “date modified” attributes remain the same, and the file won’t be included in the backup. I have considered changing the creation and modified dates of the file when it’s copied/moved to the folder, but I don’t like this idea.
Another option is to use Robocopy to create a file/folder list of everything in the shared folder, compare it to the previous list, and add new files to the backup. However, I haven’t made any progress so far.
I would appreciate any native solutions to this issue.
We use Windows 7 Ultimate x64 on all PCs in the office.
Thank you.
3 Answers
Backing up Only Files Created and Modified Yesterday
Backing up files is an essential task for any organization. It ensures that data is safe and can be easily restored in case of data loss. However, performing full backups every day can be time-consuming and inefficient. In this blog post, we will discuss how to back up only files created and modified yesterday.
Using PowerShell to Back up Files
PowerShell is a command-line tool that can be used to automate tasks in Windows. We can use PowerShell to back up files created and modified yesterday. Here’s how:
1. Open PowerShell by pressing the Windows key + X and selecting “Windows PowerShell (Admin).”
2. Navigate to the folder you want to back up using the “cd” command. For example, if your shared folder is located at C:Shared, type “cd C:Shared” and press Enter.
3. Type the following command to create a list of files that were created or modified yesterday:
Get-ChildItem -Recurse | Where-Object { $_.LastWriteTime -ge (Get-Date).AddDays(-1) }
This command lists all the files in the folder and its subfolders that were modified or created yesterday.
4. To back up these files, you can use the “Copy-Item” command. For example, to back up the files to a folder named “Backup” on your desktop, type:
Copy-Item -Path .* -Destination C:UsersYourUserNameDesktopBackup -Recurse
This command copies all the files in the current folder and its subfolders to the “Backup” folder on your desktop.
5. You can automate this process by creating a PowerShell script that runs daily using the Task Scheduler. The script should contain the commands above.
Using Robocopy to Back up Files
Robocopy is a command-line tool that can be used to copy files and folders. We can use Robocopy to back up files created and modified yesterday. Here’s how:
1. Open Command Prompt by pressing the Windows key + R, typing “cmd,” and pressing Enter.
2. Navigate to the folder you want to back up using the “cd” command. For example, if your shared folder is located at C:Shared, type “cd C:Shared” and press Enter.
3. Type the following command to create a list of files that were created or modified yesterday:
robocopy . C:UsersYourUserNameDesktopBackup /maxage:1 /s
This command copies all the files in the current folder and its subfolders that were modified or created yesterday to the “Backup” folder on your desktop.
4. You can automate this process by creating a batch file that runs daily using the Task Scheduler. The batch file should contain the command above.
Using Third-Party Software to Back up Files
There are several third-party software solutions that can be used to back up files created and modified yesterday. Some of these solutions include:
1. Acronis True Image: This software allows you to back up your entire system or individual files and folders. You can schedule backups to run automatically, and it offers advanced features such as incremental and differential backups.
2. EaseUS Todo Backup: This software allows you to back up your entire system, disks, partitions, or individual files and folders. You can schedule backups to run automatically, and it offers features such as incremental and differential backups.
3. AOMEI Backupper: This software allows you to back up your entire system, disks, partitions, or individual files and folders. You can schedule backups to run automatically, and it offers features such as incremental and differential backups.
Conclusion
Backing up files is crucial for any organization. However, performing full backups every day can be time-consuming and inefficient. By backing up only files created and modified yesterday, you can save time and ensure that your data is safe. In this blog post, we discussed how to use PowerShell, Robocopy, and third-party software to back up files created and modified yesterday. Choose the solution that best fits your needs and automate the process to ensure that your data is always safe.
There are a few different options you could consider to achieve what you’re looking for.
One option would be to use the robocopy
command to perform the backup, and use the /MINAGE:1
and /MAXAGE:1
flags to specify that you only want to copy files that were created or modified within the last day. This should include files that were created or modified yesterday, as well as any files that were moved into the shared folder within the last day (since the date modified
would have been updated when the file was moved).
For example, you could use a command like the following to perform the backup:
robocopy C:\SharedFolder D:\BackupFolder /MINAGE:1 /MAXAGE:1
This will copy all files in the C:\SharedFolder
directory (and its subdirectories) that were created or modified within the last day to the D:\BackupFolder
directory.
Another option would be to use the forfiles
command to create a list of files that were created or modified within the last day, and then use the xcopy
command to copy those files to the backup location.
To create the list of files, you could use a command like the following:
forfiles /D -1 /C "cmd /c echo @path" > filelist.txt
This will create a text file called filelist.txt
that contains a list of all files in the current directory (and its subdirectories) that were created or modified within the last day. You can then use the xcopy
command to copy the files listed in this file to the backup location, like this:
xcopy /F /I @filelist.txt D:\BackupFolder
I hope this helps! Let me know if you have any questions.
It is not necessary to specify dates when mirroring a folder through robocopy, as you can simply use the /MIR
switch instead.
Here is an example of a command that uses Robocopy to mirror two directories:
Robocopy \\SourceServer\Share \\DestinationServer\Share /MIR /FFT /Z /W:5
Here is an explanation of the switches utilized:
- The
/MIR
switch instructs Robocopy to replicate both the source and destination directories, resulting in the deletion of files at the destination if they have been removed from the source. /FFT
employs fat file timing, rather than NTFS, which offers a slightly less precise granularity. This avoids the need to rely on file timings to be precisely to the second./Z
guarantees that Robocopy can restart the transfer of a large file mid-file, rather than starting over from the beginning./W:5
minimizes the time between failures to 5 seconds, rather than the default of 30 seconds.