Store and restore gid and uid
Store and restore directories properly