CMD : How to backup data like paid software

3 min read 1 month ago
Published on Aug 02, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

In this tutorial, you will learn how to back up your data using the Command Prompt on Windows, similar to paid software solutions. We will utilize a batch file and the powerful robocopy command to automate the backup process, ensuring your important files are safely stored. This method is effective for both local and network backups, making it a versatile solution for data security.

Step 1: Create the Backup Batch File

  1. Open Notepad to create a new file.

  2. Enter the following command, updating the source and destination folders as needed:

    robocopy C:\DATA D:\Backup /E /V /LOG:C:\DATA\backup_log.txt
    
    • C:\DATA: Source folder containing the files you want to back up.
    • D:\Backup: Destination folder where the backup will be stored.
    • /E: Copies all subdirectories, including empty ones.
    • /V: Produces verbose output, providing detailed information about the copying process.
    • /LOG: Creates a log file with the backup results.
  3. Save the file with a .bat extension (e.g., backup.bat). Ensure the file type is set to "All Files".

  4. To run the batch file with administrative rights:

    • Right-click the file and select "Run as administrator".
  5. After executing, check the log file to confirm the backup was successful. It will show the backup time, number of files copied, and speed.

Step 2: Set Up a Backup Schedule

  1. Move the backup.bat file to a designated folder (e.g., C:\DATA\CMD).

  2. Open the Task Scheduler by searching for it in the Windows search box.

  3. Create a new task:

    • Name the task (e.g., “My Backup”).
    • Set the trigger to run daily.
    • Specify the execution time (e.g., 11:06 AM) and set it to start after 2 minutes.
  4. Under the Actions tab:

    • Select "Start a program".
    • Browse to the location of the backup.bat file.
    • Make sure to check "Run with highest privileges" to allow administrative access.
  5. Configure the task for Windows 10/11 under the "General" tab.

  6. Save the task and wait for the scheduled time to see the backup in action.

Step 3: Back Up Over the Network

  1. Edit the backup.bat file to back up data over the network. Add the following command:

    robocopy C:\DATA \\10.11.32.14\Backup /E /V /LOG:C:\DATA\network_backup_log.txt
    
    • Replace 10.11.32.14 with the IP address of the target computer.
    • Ensure the destination directory exists on the networked computer.
  2. Save the changes and adjust the scheduled time in Task Scheduler to test the network backup.

  3. Observe the command window during execution to verify that files are backed up correctly; note that network backups may be slower.

Step 4: Hide the Command Window

  1. Create a new VBScript file in Notepad:

    Set WshShell = CreateObject("WScript.Shell")
    WshShell.Run "C:\DATA\CMD\backup.bat", 0, False
    
    • Update the path to reflect where your backup.bat file is located.
  2. Save this file with a .vbs extension (e.g., backup.vbs).

  3. In Task Scheduler, edit the previously created task:

    • Replace the action from backup.bat to backup.vbs.
  4. Set a new execution time to test the task and confirm that the command window does not appear.

Conclusion

By following these steps, you have created a robust data backup solution using Windows CMD and Task Scheduler, similar to paid software options. This process not only automates backups but also allows for flexibility with local and network storage. Regularly check your log files to ensure backups are functioning correctly and consider additional storage solutions as your data needs grow.