Backup entire mac hard drive to a usb drive and later restore I would like to backup the entire system drive/partition to a USB hard/flash drive.  I have a 128gb usb flash drive and a 2tb usb hard drive.  I am borrowing a friends macbook air for learning swift/ios programming for a few months.  

I figured that I can back it up and restore it later for minimal inconvenience for him.  I would prefer to not have to log in or install anything on it.  I currently don't have his account password but can get it if needed.

BTW the mac is el capitan I think.  It is a different looking disk utility than I have seen in some online screenshots elsewhere.  

What I have tried:
Booting to the recovery mode using command +r.
Then I erased the usb drive (name 06192017, format osx extended journaled, GUID partition map).
Then I selected the 06192017 and selected edit>restore.
"Restore from:" I selected "macintosh HD" and clicked restore.
It takes a little while and then fails.  It says "io error" in the details.  

I have also tried to select the "macintosh HD" and select file> new image>Image from "macintosh hd"
save as: "macintosh hd"
tags: (none)
Where: 06192017 (my usb drive)
Format: compressed
encryption: none
This also seems to work for a few minutes and then fails. A box says:
com.apple.diskutility error 3

First I tried the 2tb USB hard drive and then I figured there may be a problem with that so I tried the 128gb USB flash drive.  Same results.

I am new to mac OSX.  Am I going about this all wrong?
If I'm understanding you correctly you want to backup the MacBook before you use it, then restore it a few months later so that anything you do over the next few months is wiped out and you can return it to your friend in the same condition you received it.

If this was me, what I'd do is just create a new dust2098 account for myself in the "Users &amp; Groups" panel of System Preferences, and log into that account for the next few months and then before giving the MacBook back, log into your friend's account and delete that new dust2098 account I'd created for myself.

I'm assuming you are coming from a Windows background. Macs are quite different from Windows and don't accumulate quite as much cruft as they are being used. For example, where application store their settings in the Registry in Windows, they are stored in individual plist files within your own account on a Mac. Also where random applications will regularly try to install or make changes to the c:\Windows folder (less so in more recent versions of Windows), on a Mac the /System folder and other critical locations are locked down by the System Integrity Protection (SIP) feature.