How to Create Backups Using Robocopy in Windows

I was given a task to backup some data from some Windows computers to a local NAS drive. There are many options out there, but I remembered I many years ago I used a tool called Robocopy. As usual, Windows eventually bought this company and now Robocopy is part of Windows command tools.

Open your command prompt in Windows and type robocopy just to verify. You should see a brief output telling you about robocopy.

robocopy output in command prompt Windows

Now that you made sure robocopy is available in your Windows computer we can put this little script together maybe with a great cup of coffee on your desk. I will go directly to it:

@echo off 
robocopy C:\Users\%username%\Desktop\  \\hqnas01\home\migrated_data\Desktop /MIR /XA:H /R:1 /XA:SH /FFT /XJ > C:\temp\%username%_migration.log

Explanation:

ParameterDescription
C:\Users\%username%\Desktop\Source directory.
\\hqnas01\home\migrated_data\DesktopDestination directory.
/MIRMake a mirror backup. If you delete something from the source, it will also be deleted in the destination.
/XA:HLeave out hidden files.
/R:1The number of retries if the file is locked.
/XA:SHLeave out hidden files and system files.
/FFTThis is very important when backing up to a Linux NAS. If you leave this out it will try to copy files over and over even when they are already present. Just use it!
/XJExclude junction points. Those crazy hidden My Music, My Pictures and My Videos folders under Documents.
> C:\temp\%username%_migration.logFor creating a .log file in order to see what happened. If you’re adding more than one line of backup locations you should add ‘>>’ instead of ‘>’ so you can append to the .log instead of replacing what you had before.
robocopy example with explanation

Make sure you don’t confuse source with destination or you can have catastrophic lost of data. Contact me if you have any questions. Check out my shop with cool T-shirts and mugs designed by myself.

Install Shell Completion for Docker in macOS Big Sur

Docker Desktop comes with scripts to enable completion for the docker and docker-compose commands. The completion scripts may be found inside Docker.app, in the Contents/Resources/etc/ directory and can be installed both in Bash and Zsh.

Bash

Bash has built-in support for completion To activate completion for Docker commands, these files need to be copied or symlinked to your bash_completion.d/ directory. For example, if you installed bash via Homebrew:

etc=/Applications/Docker.app/Contents/Resources/etc
ln -s $etc/docker.bash-completion $(brew --prefix)/etc/bash_completion.d/docker
ln -s $etc/docker-compose.bash-completion $(brew --prefix)/etc/bash_completion.d/docker-compose

Add the following to your ~/.bash_profile:

[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion

OR (this one worked for me!)

if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi

In my case since I’m using macOS Big Sur I wanted to change my default shell to bash. Big Sur comes with zsh as default. Below is my .bash_profile that worked for me. Yes, I used homebrew to install bash_completion. Not sure if this was necessary. Let me know what you think in the comments area below.

export PATH="/opt/homebrew/bin:$PATH"

if [ -f $(brew --prefix)/etc/bash_completion ]; then
   . $(brew --prefix)/etc/bash_completion
fi

xcrun: error: invalid active developer path MacOS

Again, I decided to come back and keep up with my path to become a full time Web Developer instead of an “IT handyman”. So, I brewed another cup of my favorite Caturra coffee varietal and poured it on my Caturra coffee varietal mug to get some code with coffee inspiration.

I opened my Terminal and wanted to check my git status:

git status

and got error:

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

I had no clue why. Then, I remembered the other day I applied an update to my macOS Mojave version. This seemed to mess things up. I found a solution somewhere. First you should try to reset you xcode install by issuing this command:

xcode-select --reset

The above did not resolve the xcrun: error: invalid active inactive issue. So, I have to re-install it by running the following on my Terminal:

xcode-select --install

It took about 5 minutes and I was able to run git commands again.

Contact me if you have any questions about this xcrun: error: invalid active or other issues with Technology. Remember I designed cool T-Shirts and coffee mugs inspired by tech and my trips. Check out my shop and let me know what you think. Thanks!

Find Command Examples Linux/MacOS

I wanted to put together some find command examples because I tend to forget this useful Linux command often. It is very important for Linux/MacOS administrators or DevOps to master the find command.

While having my favorite coffee varietal Caturra the other day I decided to put together this brief find command examples:

Syntax is simple:
find [where to start search from] [what to find] [-any options] [what to find at last]

1. Search a file with specific name.

$ find ./MyDirectory -name afile.txt

This find command will search for afile.txt in MyDirectory directory and display the results such as:

./MyDirectory/path/to/afile.txt

2. Find command examples to search for file patterns

For example if you want to find all files with a .txt extension inside the MyDirectory

find ./MyDirectory -name *.txt

If there are any .txt files you should get an output similar to:

./MyDirectory/some/path/afile.txt
./MyDirectory/some/path/bfile.txt

3. Search for empty files and directories.

This is a cool one. Let’s say you want to find those empty directories or file by just running a simple find command:

find ./MyDirectory -empty

If there are any empty files or directories you will get a list:

./MyDirectory/oneFile
./MyDirectory/twoFile

4. Find command examples to search for files with specific permissions

Another useful find command.

$ find ./MyDirectory -perm 644

The above find command example will search for files with permissions set to 644 under the /MyDirectory directory and will display a list.

Check the man pages for more useful options of the find command in Linux or MacOS. Contact me if you have any questions. Also grab one of my T-Shirt or coffee mugs designs on my shop. I design them myselft. Thanks!

Mirror a Website Using wget

The command is simple and to mirror a website using wget works fantastic. While I was crossing the Williamsburg Bridge in NYC I received a Slack chat from a customer. They wanted to backup some really old WordPress sites and just archive them as simple html files.

You can mirror a website using wget easily. Copy and paste the below into your terminal. If you’re on a mac you can install wget using brew or using your favorite method.

wget --mirror --convert-links --adjust-extension --page-requisites
--no-parent http://example.org

Explanation of the various flags:
• –mirror – Makes (among other things) the download recursive.
• –convert-links – convert all the links (also to stuff like CSS stylesheets) to relative, so it will be suitable for offline viewing.
• –adjust-extension – Adds suitable extensions to filenames (html or css) depending on their content-type.
• –page-requisites – Download things like CSS style-sheets and images required to properly display the page offline.
• –no-parent – When recursing do not ascend to the parent directory. It useful for restricting the download to only a portion of the site.
Alternatively, the command above may be shortened:
wget -mkEpnp http://example.org

wget will create a directory with the website’s name you’re mirroring. Enjoy and let me know if you have any questions by leaving a comment. You can also check out my shop for cool tech T-Shirts and Coffee mugs.

How to Change MacOS hostname using the Terminal

Hola! the other day I had a need to change a MacOS hostname using the Terminal. I did not have access to a GUI and had to do this remotely. Chagning the hostname using MacOS Terminal is quite simple and is my favorite method. This is why I decided to document this little how to.

To open your Terminal go to Applications/Utilities or just do a Spotlight Search and type Terminal.

Once in your Terminal type:

scutil --set ComputerName "name"

Replace “name” with the computer name you wish to assign and press return. Next, you need to set your local network to Bounjour-based services by typing this command:

scutil --set LocalHostName "name"

Again, replace “name” with the same name you used before.

One last one is to set the name when connecting via SSH and the name shown on your Terminal. Simple type:

scutil --set HostName "name"

Once again, replace “name” with the same name you used before. If you get an authentication window enter your password. This account must have admin rights to make the changes.

After you set all of the above to your desired computer name/MacOS hostname you can verify your MacOS hostname by typing this command:

scutil --get HostName

You should see the new MacOS hostname/computer name displayed on your terminal. Thank you and if you like to support me you can get my Code with Coffee T-Shirt design. I make all designs based in NYC.

The requested image’s platform (linux/arm64) does not match the detected host platform

When I was testing Docker’s initial tutorial when you download for the first time I got the error:

The requested image's platform (linux/arm64) does not match the detected host platform (linux/amd64) and nospecific platform was requested.

It sucks because I got a new MacBook Pro M1 and I did not know about these issues with arm64 chips and images. Trying to play with the tutorial while having great coffee from Latin America I got stuck when trying to run the MySQL image in my compose file.

Searching around I found two options to resolve this. See below:

Option 1: Add the flag –platform linux/arm64

This will tell your MacOS M1 what platform to use. Brief example:

docker run -d \
    --platform linux/amd64 \
    --network todo-app --network-alias mysql \
    -v todo-mysql-data:/var/lib/mysql \
    -e MYSQL_ROOT_PASSWORD=secret \
    -e MYSQL_DATABASE=todos \
    mysql:5.7

Option 2: Use MariaDB instead of MySQL

As of this post MariaDB offers official support for ARM64 architecture. Use this docker command instead as an example:

docker run -d \
  -v todo-mysql-data:/var/lib/mysql \
  -e MYSQL_ROOT_PASSWORD=secret \
  -e MYSQL_DATABASE=todos \
  mariadb:10.5

Feel free to contact me if you have any questions. Also, if you like to code with coffee make sure to checkout my shop with inspirational coffee mugs and T-Shirts.

MacOS Restarts and a Message Shows

The other day after having my favorite Latin America coffee I went to take a walk around Seaport in New York City. When I came back my Macos restarted with error message saying that my MacOS restarted and if I wanted to send a report to Apple. I pressed ignore and put on my new Code with Coffee T-Shirt.

The most likely cause is faulty software. A kernel panic can also be caused by damaged or incompatible hardware, including external devices attached to your Mac. If the kernel panic is caused by a known problem, the faulty software is identified. To make sure that this software doesn’t continue to cause kernel panics, move it to the Trash.

If not a faulty software and your MacOS continues to reboot with kernel panics, try these:

  1. Restart your Mac in safe mode. If it successfully starts up in safe mode, choose Apple menu > App Store, click Updates, then install any available updates.
  2. Uninstall any plug-ins or other enhancement software from manufacturers other than Apple. If you recently updated macOS or an app, plug-ins and other software that worked in the past may no longer be compatible. Read the manufacturer’s documentation (including Read Me notes) to be sure the software is compatible with your version of macOS.
  3. Disconnect all devices except for an Apple keyboard and mouse. Remove hardware upgrades from other manufacturers, such as random-access memory (RAM) and Peripheral Component Interconnect (PCI) cards. Then try restarting your Mac.
  4. If this resolves the issue, reconnect one device at a time, restarting your Mac after reconnecting each one, until you determine which device is causing the problem.
  5. Use Apple Diagnostics to diagnose problems with your computer’s internal hardware, such as the logic board, memory, and wireless components.

You can also check MacOS Console to find out more details about why your MacOS restarted.

Find Public IP Address using Linux Command Line

The other day I had to ssh into a RedHat Linux server to help a friend. My friend wanted to find the public IP address using Linux command line. This is simpler than what I imaged.

After having one of my favorite Latin America coffee from Peru I was able to find the answer. Use these simple commands after opening your Terminal/Command line on Linux:

  • Using the dig command type:
    • dig +short myip.opendns.com @resolver1.opendns.com
  • or you can use this one:
    • dig TXT +short o-o.myaddr.l.google.com @ns1.google.com

You can now see your public IP address on your Linux terminal.

Find Public IP Address using Linux
Find Public IP Address using Linux

Create Desktop Shortcut Windows 10 For All Users

The other day a friend asked me to create a desktop shortcut in Windows 10 for all users. I have been using other operating systems for a while and have been trying to stay away from Windows.

After taking a walk in New York City I refreshed my mind and found a way to create this desktop shortcut for all users in Windows 10. These are the steps:

  • Login as Administrator in Windows 10 (Your local Admin account)
  • Go to your C drive > Users > Public > Public Desktop (“Public Desktop” is usually a hidden file, so you need to do this – in your File Explorer select ‘View’ and then select the checkbox ‘Hidden Items’
desktop shortcut Windows 10
Show hidden files Windows 10

Now just drag and drop your shortcuts into the Public Desktop and it will show for all your users in Windows 10.