CopyFolders: Fast & Simple Folder Duplication Tool

How to Use CopyFolders to Mirror Directory Structures

Mirroring directory structures copies the folder hierarchy from a source location to a target location while optionally copying files, timestamps, permissions, and attributes. This guide shows a practical, step-by-step workflow using the hypothetical command-line tool “CopyFolders” to mirror directories reliably on Windows, macOS, and Linux. Examples assume CopyFolders is installed and available in your PATH.

1. Basic mirror (folders only)

Copy just the directory tree without files.

  • Command:

Code

copyfolders –mirror-folders /path/to/source /path/to/target
  • What it does:
    • Creates the same nested folders under /path/to/target as exist in /path/to/source.
    • Skips file contents.

2. Mirror folders and files (full mirror)

Copy folders and files so target is a full mirror of source.

  • Command:

Code

copyfolders –mirror /path/to/source /path/to/target
  • Key behavior:
    • Replicates files and folders.
    • Overwrites differing files in target to match source.
    • Leaves unchanged files intact for speed.

3. Preserve timestamps, permissions, and ownership

Keep metadata consistent between source and target (useful for backups and deployment).

  • Command:

Code

copyfolders –mirror –preserve=times,perms,owner /path/to/source /path/to/target
  • Notes:
    • Ownership preservation may require elevated privileges (root/Administrator).
    • On Windows, owner mapping may behave differently; test on a small sample first.

4. Exclude patterns and include selective content

Exclude temporary files or include only certain file types.

  • Command (exclude):

Code

copyfolders –mirror –exclude=”.tmp, nodemodules,.bak” /path/to/source /path/to/target
  • Command (include only):

Code

copyfolders –mirror –include=”.md, *.txt” /path/to/source /path/to/target
  • Tips:
    • Use comma-separated globs.
    • Exclusions are applied before copying; test patterns with a dry run.

5. Dry-run and logging for safety

Preview changes before making them and save logs for auditing.

  • Command:

Code

copyfolders –mirror –dry-run –log=/var/log/copyfoldersmirror.log /path/to/source /path/to/target
  • What to check:
    • Which files will be added, updated, or removed.
    • Any permission or path errors.

6. Handling deletions on target

Make target exactly match source by removing files/folders not present in source.

  • Command:

Code

copyfolders –mirror –delete-extraneous /path/to/source /path/to/target
  • Warning:
    • This permanently deletes items in target that don’t exist in source. Use dry-run first.

7. Performance and parallelism

Speed up large copies with parallel file transfer and partial checksums.

  • Command:

Code

copyfolders –mirror –jobs=8 –checksum=partial /path/to/source /path/to/target
  • Guidance:
    • Increase jobs for multi-core systems and fast I/O.
    • Partial checksums are faster but slightly less thorough than full checksums.

8. Scheduling automated mirrors

Run CopyFolders regularly using cron (Linux/macOS) or Task Scheduler (Windows).

  • Example cron entry (daily at 2:00 AM):

Code

0 2 * * * /usr/bin/copyfolders –mirror –preserve=times,perms /data/source /data/target –log=/var/log/copyfoldersdaily.log

9. Troubleshooting common issues

  • Permission denied: run with sudo/Administrator or adjust permissions.
  • Path length errors (Windows): enable long paths or use UNC paths.
  • Symlink handling: check tool options for following or recreating symlinks (e.g., –follow-symlinks vs –copy-symlinks).

10. Example end-to-end scenario

Mirror /home/projects to /backup/projects nightly, preserve metadata, exclude build artifacts, and delete extraneous files:

Code

copyfolders –mirror –preserve=times,perms –exclude=“node_modules, build, *.tmp” –delete-extraneous –jobs=4 –log=/var/log/projects_mirror.log /home/projects /backup/projects

Follow with a dry-run the first time and examine logs regularly.

If you want, I can adapt these commands for Windows PowerShell syntax or generate a ready-to-use cron or Task Scheduler entry for your environment.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *