How to clear the hard disk of windows server when it is full?

This article mainly introduces some disk cleaning methods that I summarized during the maintenance of windows server. It's an honor to be of help to you.

1. Clean up the C drive

When we use the server, we basically don’t install software on the C drive, so after using it for a long time, we find that the C drive is full, indicating that there is insufficient space.

1. System32 log files

Open the folder C:\Windows\System32\LogFiles. Delete all (skip files in use).
insert image description here

2. IIS log files

Open the folder C:\inetpub\logs\LogFiles. Delete all (skip files in use).
insert image description here

3. Cache files of .Net Framework

.Net Framework will also have a lot of cache files:
insert image description here
find the Temporary ASP.NET Files file (if any), and clear the cache files.
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files
insert image description here

4. Clean up other unnecessary files

After the server IIS log is cleared, clean up the following files:
C:\WINDOWS\PCHealth\ERRORREP\QSIGNOFF
C:\WINDOWS\PCHealth\ERRORREP\UserDumps
C:\Windows\Temp

5. The virtual memory is moved from the c drive to other hard drives

By default, the virtual memory of the server is on the C disk. Transferring the virtual memory to other disks, such as the D disk or the E disk, can increase the space of the C disk. Click here to view the virtual memory setting method .
Setting virtual memory to other disks requires restarting the server to take effect. Restarting the server can also close many cache files generated by the system.
Deleting unnecessary files has little effect on cleaning the C drive. The main thing is to clean up the IIS system log and virtual memory settings can solve the server c Insufficient disk space
Lastly, many program paths default to the C drive. During installation, the path can be changed to the D drive or E drive. Many of the C drives are system files, which are not easy to clean.

6. .net runtime cleanup

No .NET programmer is new to .NET. .NET is an open source developer platform created by Microsoft, which is used to generate many different types of applications. Taking the
program and function interface of a win server server in our company as an example, we can see that the .NET operating environment occupies A lot of disk space, and the .net operating environment is forced to be installed on the C drive. Here we have two cleanup options:
insert image description here

1. Clean up the .NET version that is no longer used

It can be seen from the figure that the .net versions are .NET5.0, .NET Core 3.1, and .NET Core 2.2.
Here we need to determine whether the web application deployed on the server uses the relevant .NET version. For example, since all the company's web applications have been upgraded from the early .NET Core 2.2 to .NET5.0 and .NET Core 3.1, .NET core 2.2 can be uninstalled at this time. You can continue to consider upgrading to .NET5.0 later. This will clear up a lot of space.

2. Use .NET Rumtime instead of .NET SDK

.NET SDK is an SDK provided by Microsoft for developing, compiling and debugging .NET applications. To put it bluntly, it is for Visual Studio. Generally speaking, there is no need to install VisualStudio on the server to develop .NET applications, only to deploy .NET applications.
Microsoft's introduction to .NET SDK:
insert image description here
Microsoft's introduction to .NET Rumtime:

insert image description here
Therefore, we can uninstall the .NET SDK and replace it with the corresponding version of the .NET Runtime. C drive space will be much smaller.

2. Other software cleaning

1. Clean up the major software logs

1.1 Zen way:

ZenTao backup file path: C:\xampp\zentao\tmp. The longer you use it, the more it takes up, so you can delete it.
insert image description here

1.2 Database:

1.2.1 Sql server:

1.2.1.1: Defragment the index

SQL Server generates index fragmentation during use. We can compress space by defragmenting indexes.

SQL Server SQL statement to view database index fragmentation:

-- SQL Server查看数据库索引碎片情况
SELECT OBJECT_NAME(ind.OBJECT_ID) AS TableName, 
ind.name AS IndexName, indexstats.index_type_desc AS IndexType, 
indexstats.avg_fragmentation_in_percent 
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, NULL) indexstats 
INNER JOIN sys.indexes ind  
ON ind.object_id = indexstats.object_id 
AND ind.index_id = indexstats.index_id 
WHERE indexstats.avg_fragmentation_in_percent > 30 
ORDER BY indexstats.avg_fragmentation_in_percent DESC

Running results:
insert image description here
Four methods of index defragmentation:
1) Delete the index and rebuild
2) Use the DROP_EXISTING statement to rebuild the index
3) Use the ALTER INDEX REBUILD statement to rebuild the index
4) Use ALTER INDEX REORGANIZE to reorganize the index
For details, see: SQL Server Index Maintenance - Index fragmentation and fill factor
We mainly use method 3 Rebuild (rebuild index) and method 4 Reorganize (reorganize index).
Rebuilding the index, as the name implies, is to delete the original index and rebuild the index. The degree of space recovery is high, the operation is more dangerous, and the operation is longer.
Reorganizing the index, as the name implies, means not deleting the original index, but reorganizing the index on the basis of the original one. Space can be recovered to a certain extent, but the operation is relatively safe and the operation speed is fast.

SQL Server automatically reorganizes the SQL statement of the index:

-- SQL Server重新组织索引
SET NOCOUNT ON
DECLARE @Objectid INT, @Indexid INT,@schemaname VARCHAR(100),@tablename VARCHAR(300),@ixname VARCHAR(500),@avg_fip float,@command VARCHAR(4000)
DECLARE IX_Cursor CURSOR FOR
SELECT  A.object_id,A.index_id,QUOTENAME(SS.NAME) AS schemaname,QUOTENAME(OBJECT_NAME(B.object_id,B.database_id))as tablename ,QUOTENAME(A.name) AS ixname,B.avg_fragmentation_in_percent AS avg_fip FROM sys.indexes A inner join  sys.dm_db_index_physical_stats(DB_ID(),NULL,NULL,NULL,'LIMITED') AS B 
ON A.object_id=B.object_id and A.index_id=B.index_id 
INNER JOIN SYS.OBJECTS OS ON A.object_id=OS.object_id
INNER JOIN sys.schemas SS ON OS.schema_id=SS.schema_id
WHERE B.avg_fragmentation_in_percent>10 and B.page_count>20    AND A.index_id>0 AND A.IS_DISABLED<>1--AND OS.name='book'
ORDER BY tablename,ixname
OPEN IX_Cursor
FETCH NEXT FROM IX_Cursor INTO @Objectid,@Indexid,@schemaname,@tablename,@ixname,@avg_fip
WHILE @@FETCH_STATUS=0
BEGIN
    
    IF @avg_fip<30.0
    SET @command=N'ALTER  INDEX '+@ixname+N' ON '+@schemaname+N'.'+ @tablename+N' REORGANIZE ';
    IF @avg_fip>=30.0 AND @Indexid=1
        BEGIN
        IF EXISTS (SELECT * FROM SYS.columns WHERE OBJECT_ID=@Objectid AND max_length in(-1,16))
        SET @command=N'ALTER  INDEX '+@ixname+N' ON '+@schemaname+N'.'+ @tablename+N' REBUILD ';
        ELSE
        SET @command=N'ALTER  INDEX '+@ixname+N' ON '+@schemaname+N'.'+ @tablename+N' REBUILD '+N' WITH (ONLINE = ON)';
        END
    IF @avg_fip>=30.0 AND @Indexid>1
        BEGIN    
        IF EXISTS (SELECT * FROM  SYS.index_columns IC INNER JOIN SYS.columns CS ON CS.OBJECT_ID=IC.OBJECT_ID AND CS.column_id=IC.column_id                   WHERE  IC.OBJECT_ID=@Objectid AND IC.index_id=@Indexid AND CS.max_length in(-1,16) )
        SET @command=N'ALTER  INDEX '+@ixname+N' ON '+@schemaname+N'.'+ @tablename+N' REBUILD ';
        ELSE
        SET @command=N'ALTER  INDEX '+@ixname+N' ON '+@schemaname+N'.'+ @tablename+N' REBUILD '+N' WITH (ONLINE = ON)';
        END
    --PRINT @command
    EXEC(@command)
 
 FETCH NEXT FROM IX_Cursor INTO @Objectid,@Indexid,@schemaname,@tablename,@ixname,@avg_fip
END

CLOSE IX_Cursor
DEALLOCATE IX_Cursor

Running result:
insert image description here
insert image description here
manually rebuild the index

insert image description here
insert image description here

1.2.2 Mysql:

1.2.2.1 Mysql binlog log cleaning:

The binlog log in MySQL records the changes of data in the database, which is convenient for data recovery based on time point and location. However, the binlog will also increase day by day and take up a lot of disk space. Therefore, it is necessary to use correct and safe binlog method to clean up some useless logs.
Refer to the article for specific operations: How to correctly clean up binlog logs in mysql

1.3: Tencent Computer Manager smart backup folder qqpcmgr_docpro

If you usually use Tencent PC Manager, it will generate a qqpcmgr_docpro file. This directory is generated by Computer Manager-Document Guardian and is used to store files generated by "Smart Backup".
insert image description here
This is Tencent's official documentation:
insert image description here
Usually pay attention to delete or limit the size.

2. Commonly used hard disk cleaning tools

to be continued


Summarize

Tip: Here is a summary of the article:
For example: the above is what I will talk about today. This article only briefly introduces the use of pandas, and pandas provides a large number of functions and methods that allow us to process data quickly and easily.

Guess you like

Origin blog.csdn.net/guigenyi/article/details/128420654