0
0
Bash Scriptingscripting~10 mins

Backup automation script in Bash Scripting - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a backup directory if it does not exist.

Bash Scripting
if [ ! -d [1] ]; then
  mkdir -p /backup
fi
Drag options to blanks, or click blank then click option'
A/tmp
B/home
C/backup
D/var
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong directory path.
Forgetting the exclamation mark to negate the condition.
2fill in blank
medium

Complete the code to copy all files from /data to the backup directory.

Bash Scripting
cp -r /data/* [1]
Drag options to blanks, or click blank then click option'
A/backup
B/tmp
C/var
D/home
Attempts:
3 left
💡 Hint
Common Mistakes
Copying to the wrong directory.
Forgetting the -r flag for directories.
3fill in blank
hard

Fix the error in the code to archive the backup directory into a tar.gz file.

Bash Scripting
tar -czf [1] /backup
Drag options to blanks, or click blank then click option'
Abackup.tar
Bbackup.gz
Cbackup.zip
Dbackup.tar.gz
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong file extension like .zip or .gz alone.
Omitting the -z flag for compression.
4fill in blank
hard

Fill both blanks to check if the backup archive exists and print a success message.

Bash Scripting
if [ -f [1] ]; then
  echo [2]
fi
Drag options to blanks, or click blank then click option'
Abackup.tar.gz
B"Backup completed successfully!"
C"Backup failed!"
Dbackup.zip
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for wrong file name.
Printing failure message on success check.
5fill in blank
hard

Fill all three blanks to create a timestamped backup filename and archive the backup directory.

Bash Scripting
timestamp=$(date +[1])
backup_file=[2]_$timestamp.tar.gz
tar -czf [3] /backup
Drag options to blanks, or click blank then click option'
A"%Y%m%d_%H%M%S"
Bbackup
C$backup_file
Dbackup.tar.gz
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong date format string.
Not using the variable for the archive filename.
Hardcoding the archive filename instead of using timestamp.