Today I will share my technique on how I clean up AWS EC2 storage for not getting it full. Many people using AWS Instance for hosting their website face this common problem of storage full in a few days and the website shutdowns.
So Let’s Begin To Clean Up AWS EC2 Storage.
1. First, you have to connect your AWS instance with Putty SSH. Don’t know how to do that don’t worry I will put a video which u can view and connect your AWS to Putty SSH.
The video is in Hindi if you don’t understand the language no worry just follow the steps and you are done or you can search on youtube.com for your compatible language.
2. After you are connected to AWS instance using Putty SSH you will see this window.
Now we can see we are logged in as bitnami now we have to check how much storage is filled first. For that, we will use the following command.
Now you will see storage used and storage left in your instance.
As you can see my 11 GB is used from 30 GB and only 18 GB is remaining and my website size may be hardly 500 mb so who is using rest of your memory you will get the answer below.
Now rest of the process can only be done by root use so we have to go as root user for that we have to the command given below.
this command will make you log in as root user after that you will see a window like this.
3. Now after we are in the root directly we have to find the biggest file which is filling our space in most of the cases it the MySQL bin logs files which are not pruned and fill our space in my case also it’s the bin logs file which is creating an unnecessary log file of 1.1 GB every day and filling up my instance storage.
To find it enter the following command.
du -hs /opt/bitnami/*/*/* | sort -rh | head -5
-5 is the number of list file, you can replace it with your number you think your log files should be.
Now you will see the files which are big and filling your instance space. You, will see everything in detail with file size file directory and file name.
4. Now that what we have to do is check this size of the binlog folder first using this command.
du -hs /opt/bitnami/mysql/data
Now you will see the size of your binlog files folder.
As you can see my 7.5 GB is used just for the purpose of bin logging and the prune function is not working correctly.
5. So my solution is to prune it manually for that we have to go to the directly first where the files are stored. For that, we will use the following command.
6. Now we have entered the following directory we list all the file present in the directory. For that we will use the following command.
Now you can see all the binlog file present in the folder which is using you instance space unecessarily.
7. So now we have to prune(delete) it manually. We will only delete the old binlog files leaving 2 latest file.
Warning: Please make a backup of your website before practising this method this technique worked for me but cannot guarantee will work for everyone so before you apply this technique to yours make sure you backup your site.
Now we will use the follow command to delete the files.
Now after command enter the file names you wanna prune(delete) in my case it is binlog.000004 to binlog.000011 and will leave the latest two binlogs and prune rest.
Now lets check our storage again after prune.
As you can see previous my used storage was 11 GB and now it just 5.1 GB, 3.1 GB is used by system rest is used by our website.
So this way we can clean up AWS EC2 storage in we steps. Just do it ones in a week and thats all your site will never face the storage full issue.
If you like this article make sure you subscribe so that you dont miss our latest post.
For more such articles you can visit “Computer & Technology“.