full backup of woocommerce and restore cart contents

How to get a full backup of the woocommerce shopping cart and restore it?

I receive a cart backup with this code:

$ cart = WC () -> cart-> get_cart_contents ();
$ cart = WC () -> cart-> get_cart ();

for the restoration, I use it but I do not work:

WC () -> cart-> set_cart_contents ($ cart);