O
O
OlZhi2021-11-24 13:44:37
Backup
OlZhi, 2021-11-24 13:44:37

How to backup a directory?

I have a sample code, but this code backs up the database. How to backup a directory and can it be written in one file or in another already?

Database backup code

#!/bin/bash

FILES_DIR="/var/www"
BACKUP_DIR="/mnt/backup"

TIMESTAMP=`date +"%Y-%m-%d_%H-%M-%S"`

mount $BACKUP_DIR

mysqldump -uroot -hlocalhost -pSuper2021 --all-databases > $BACKUP_DIR/$TIMESTAMP.sql
tar -czvf $BACKUP_DIR/$TIMESTAMP.tar.gz $FILES_DIR/

umount $BACKUP_DIR

exit 0;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Drno, 2021-11-24
@OlZhi

you can just copy the directory using the cp command,
for example
#create a folder
mkdir /mnt/backup/folder_with_date #copy
cp
/var/www /mnt/backup/folder_with_date
How to create a folder based on the date - I won’t tell you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question