Datto Windows Agent: Error: "Snapshot not in a good state - State 5 Error 0x00000028"
Topic
Troubleshooting steps to take a backup fails to complete using the Datto Windows Agent and the agent logs show the error:
Snapshot not in a good state - State 5 Error 0x00000028. Deleting snapshot set...
Environment
- Datto Windows Agent 2.1.x to 2.7.x
Description
Often with this issue the GUI will show the generic backup error: "Critical backup failure during data transfer" . Always check the agent logs for more specific information and error reporting. The error mentioned in the title is caused by the Copy on Write (COW) file for one or more volumes being highly fragmented.
Resolution
The COW file is not used in later Datto Windows Agent versions. Updating the windows agent to the latest possible for a given system is recommended.

IMPORTANT It is possible to have more than one fragmented volume, so you should perform the below steps on each volume that is being backed up.
Pause backups for the agent and cancel any active backup jobs
Download and extract the Microsoft program Contig from the Sysinternals website(external link).
Open an elevated command prompt and navigate to the download location of Contig.
Run the following commands to check the COW (.ctl) file for fragmentation:
sc stop dattofsf
contig.exe -a C:\datto.ctl
Check the output for the value ${file} is in ${x} fragments.
EXAMPLE
C:\Users\Administrator\Downloads\Contig>Contig.exe -a C:\datto.ctl Contig v1.8 - Contig Copyright (C) 2001-2016 Mark Russinovich Sysinternals C:\datto.ctl is in 10130 fragments Summary: Number of files processed: 1 Number unsuccessfully procesed: 0 Average fragmentation : 10130 frags/filRepeat steps one through five for each volume included in the backup.
Once the files have been checked, if fragmentation is not above 10240, go ahead and start the dattofsf service again:
sc start dattofsf

Perform the following steps for any COW file that shows 10240 fragments or more.
Open an Administrator command prompt.
In directory c:\Program Files\Datto\drivers\util, reset the snapshots with the following command:
DattoSnapshot.exe -ra
Perform the following command to stop the dattofsf service.
sc stop dattofsf
Run the following commands (from the directory you installed Contig in) against each datto.ctl file per volume that you are backing up.
Contig.exe -v C:\datto.ctl
Contig.exe -a -v D:\datto.ctl
After running the commands, run the same commands above again to validate if contig determined that the file can be optimized. This should show the Fragmentation number close to 1 or substantially lower then the previous analysis.
NOTE If the file can be optimized, it is moved into the free space of the disk to clear the current fragmentation.

Go into the root directory of each volume where COW fragmentation was high & delete the datto.ctl & datto.mif file.
NOTE datto.ctl & datto.mif are system level files so you may need to go into windows explorer options to show system protected files.
Perform a full defragment of each volume where COW fragmentation was high.
Once Defrag is complete, start the service again with
sc start dattofsf
Start a new backup. This will re-create the .ctl & .mif file.
Free space fragmentation
The fragmented CoW file issue could persist intermittently if the volume has significant free space fragmentation. If you run the contig program with the "-f" parameter against the volume, you can see the largest contiguous free space block, and the number of free space fragments.
EXAMPLE
C:\Users\kwagner\Downloads\Contig>Contig.exe -f C:
Contig v1.8 - Contig
Copyright (C) 2001-2016 Mark Russinovich
SysinternalsSummary:
Free cluster space : 21080526848 bytes
Free space fragments : 23639 frags
Largest free space block : 3962826752 bytes
If the block is small, and there are a lot of free space fragments, that can signal that the volume needs to be defragmented with a bias towards contiguous free space, not necessarily defragmenting the other files. Try running Contig.exe -f C:\
and Contig.exe -a C:\
to see the free space and file fragmentation to make a determination.

Contact Datto Technical Support for assistance.