-1

Let me assure you that the operations I'm going to perform is on my live production server, so there is no scope for any error.

The server as well as my local machine are using Linux operating system only.

I'm able to login through the terminal on my machine with following command and entering the password :

root@32.77.491.13

Then again I typed in following command to go into the directory '/var/www' on the server :

cd /var/www

Now what I want to create is create a folder titled 'website_backup_19_02_2016' inside the folder 'var/www/'

In the newly created folder 'website_backup_19_02_2016' all the files and folders present in '/var/www/' should be copied (except the newly created folder 'website_backup_19_02_2016').

Can someone please provide me the exact set of command in sequential manner so that by executing them I can take backup of my website without any hassle.

halfer
  • 19,824
  • 17
  • 99
  • 186
PHPLover
  • 1
  • 51
  • 158
  • 311
  • Why not copy it to a destination outside `/var/www`? Even if this works the first time around, you will copy all your old backups into the newest one if you repeat the same procedure (as per your requirements). – jsfan Feb 19 '16 at 06:07

2 Answers2

1

You can issue below commands :-

1) Create directory

# mkdir /var/www/website_backup_19_02_2016

2) Copying files except website_backup_19_02_2016 directory. You can achive this using rsync tool.

# cd /var/www/
# rsync -av --progress * website_backup_19_02_2016/ --exclude website_backup_19_02_2016/

" * " --> for all your files and directories in /var/www/

Note :- You can run a dry run with rsync command to check which files and directories will actually copied. This will be important for you.

rsyn -n --progress * website_backup_19_02_2016/ --exclude website_backup_19_02_2016/

Read more options for rsync from man page.

Siddharth sharma
  • 1,717
  • 1
  • 13
  • 8
  • Thanks for your answer. Just explain me what is meant by dry run and why it is necessary? – PHPLover Feb 19 '16 at 06:59
  • when you use rsync and don’t know what exactly your command going do. Rsync could really mess up the things in your destination folder and then doing an undo can be a tedious job. Use of this option will not make any changes only do a dry run of the command and shows the output of the command, if the output shows exactly same you want to do then you can remove ‘-n or --dry-run‘ option from your command and run on the terminal. – Siddharth sharma Feb 19 '16 at 07:03
1

This should work

cd /var/www
mkdir website_backup_19_02_2016
rsync -av --exclude='/var/www/website_backup_19_02_2016' /var/www /var/www/website_backup_19_02_2016

This answer your question but - if I were you - I would use a different date format (YYYY-MM-DD) that works better for listing and sorting. This would be easy to run in a script:

bck=website_backup_$(date +%Y-%m-%m)
cd /var/www && mkdir ${back}
rsync -av --exclude="$bck" /var/www/{,/$bck}
mauro
  • 5,730
  • 2
  • 26
  • 25