Objective: Create a
.sh script to backup directories in
It is easy to accidentally delete a Docker container and the volume data.
The difference is using
-v flag when you call
docker-compose downmeans that your volume data is saved
docker-compose down -vmeans that your volume data is deleted
It is easy to remove the wrong folder.
For example, you have two folders:
What happens if you want to remove a directory using
rm -rand you select the wrong folder?
You want to do this:
rm -r my-docker-project-temp
But, you accidentally push Enter before using autocomplete to list the full path, which is
rm -r my-docker-project-temp.
What happens if your project database becomes corrupt? Or, you are doing database maintenance and you realized that you just removed the wrong table.
Your task is to write a script that copies specific folders from
First, make a list of which folders you want to backup
ls -lhto view the folders in your home directory
Next, create the
Copy the files manually to verify that the command work
cpcommand to copy the folders.
cp -rfv source destination
cpcopies files or folder from the source to the destination.
-rflag copy recursively (directories).
-fflag does not prompt the user when overwriting existing data.
-vflag enables verbosity and display the results.
sourceis the source directory or file.
destinationis the destination directory or file.
Use the full path in the script: use
For example, you might want to use this command to backup your VPN data:cp -rfv /root/docker-openvpn /var/user-backups/docker-openvpn
Verify that the data copied
Copy them again manually to verify that the commands work without user interaction.
Then, add the commands to the script.
Execute that script to verify that the files copied.