Hi & Welcome to AskUbuntu,
Well, I'm not sure why
/var/www directory is been owned by root while technically it should be
www-data who'll be the owner & the group as default. Nevertheless, the simplest way to achieve this is using below script which I use to compress some of my directories. I'm using
tar command instead.
Creating a shell script
TIME=`date +%F-%H%M%S` # time stamp to the backup file
FILENAME="backuup nam-$TIME.tar.gz" # defining the format of the file name while backing up
SRCDIR="/home/parth/to/source" # Location of the backup directory
DESDIR="/home/path/to/destination" # Destination of the backup directory (where you need to backup)
tar -cpzf $DESDIR/$FILENAME $SRCDIR # Executing the command
- save the script (with CTRL+O & enter). Then exit (with CTRL+X).
Executing the command
- Simply run
sudo sh filename.sh to perform (sudo will run with root previledge)
You may also add this to a cronjob which will automate the process according to your needs. This bash script append a time stamp and backup on an incrimental basis. Its just a simple script that I took and altered to your ease.
Refer official Ubuntu Documentation on Shell Scripts & bash script which I took from BroExperts.
Hope it helps!